【问题标题】:apply bootstrap theme globally using react styled-components使用 react styled-components 全局应用引导主题
【发布时间】:2019-03-03 12:49:12
【问题描述】:

我尝试搜索示例,显示如何使用 styled-components 全局导入和使用引导主题,但只能找到显示组件样式的示例(例如 https://github.com/aichbauer/styled-bootstrap-components)或在 injectGlobal 中重新创建 css(例如 @987654322 @)。

我不能把它们全部放在一起,所以我想问一下导入引导 css 的程序是什么,以便字体、字体大小等设置在全局范围内生效。 我在想这样的事情:

    injectGlobal`
  @import url(‘url.to.bootstrap.css ');

  /* Hopefully there is a solution where I don't have to recreate these 
     settings because its achieved by the above import
  body {
    padding: 0;
    margin: 0;
    font-family: Roboto, sans-serif;
  }
  */
`

更新:这按预期工作。谢谢西蒙。

injectGlobal`
  @import url(‘https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css');
`

【问题讨论】:

标签: css reactjs styled-components


【解决方案1】:

你有两个选择:

import加载css:

import 'path/to/bootstrap.css'

或者像你提到的@import

injectGlobal`
 @import url(‘https://path/to/bootstrap.css');
`

也许这篇文章可以帮助你: https://dev.to/spences10/getting-started-with-styled-components---5c04

【讨论】:

猜你喜欢
  • 2020-02-13
  • 2018-02-09
  • 2018-08-18
  • 2021-07-13
  • 2021-01-09
  • 2019-02-18
  • 2018-06-23
  • 2018-08-16
  • 2019-08-23
相关资源
最近更新 更多