【问题标题】:How to edit style in react-bootstrap?如何在 react-bootstrap 中编辑样式?
【发布时间】:2017-03-27 15:49:42
【问题描述】:

我正在使用this boilerplate 创建一个基于反应的应用程序。我有这个基本代码:

App.js:

 render() {
    const styles = require('./App.scss');
    return (
      <div className="styles.app">
        <Helmet {...config.app.head}/>
        <Navbar fixedTop className={styles.navbar}>
          <Navbar.Header>
            <Navbar.Brand>
              <IndexLink to="/" activeStyle={{color: '#33e0ff'}}>
                <div className={styles.brand}/>
              </IndexLink>
            </Navbar.Brand>
            <Navbar.Toggle/>
          </Navbar.Header>
        </Navbar>
      </div>
    );
  }

App.scss:

.app {
  .navbar{
    background: #1b6d85;
  }
  .brand {
    position: absolute;
    $size: 40px;
    top: 5px;
    left: 5px;
    display: inline-block;
    background: #2d2d2d;
    width: $size;
    height: $size;
    background-size: 80%;
    margin: 0 10px 0 0;
    border-radius: $size / 2;
  }
  nav :global(.fa) {
    font-size: 2em;
    line-height: 20px;
  }
}
.appContent {
  margin: 50px 0; // for fixed navbar
}

对于Navbar 标签,我尝试使用模板中的className 和我在网上一些问题中看到的bsStyle。我无法成功编辑 react-bootstrap 的任何组件。 如果我错过了 react-bootstrap 网站上的文档,也请指点我。谢谢。

【问题讨论】:

  • 您是否在 index.html 中添加了 bootstrap.min.css 和 bootstrap.min.js 作为依赖项
  • 不,我不知道是否需要将样式添加到 react-bootstrap。你能提供一些参考吗?

标签: css reactjs react-bootstrap


【解决方案1】:

React-bootstrap 需要 bootstrap.css 作为文件中的依赖项。将它添加到您的 index.html 中,它应该适合您。

请参阅此文档:

React-bootstrap guide

【讨论】:

  • 我在手机上,所以我很难写一个详细的解释。但是答案中的链接应该对您有所帮助
  • 我认为您应该查看我提到的样板文件。它的工作方式有点不同,我认为它已经配置了引导程序。
  • 我可以从文档中了解到它们使用的是本地样式,因此您可以在下载后尝试在文件中导入 bootstrap.min.css。另外为了直接指定样式而不明确提及它们,请在 readme.md 文件中进行必要的更改
  • 你不应该需要 bootstrap.js。 React-Bootstrap 的全部意义在于允许使用惯用的 React 进行 Bootstrap 的样式设置。 bootstrap.js 无法做到这一点。
  • @mattsmith 我同意 bootstrap.js 不是必需的,但样式表是必需的。正如反应文档中提到的那样
猜你喜欢
  • 2020-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-26
  • 2019-08-07
  • 1970-01-01
  • 1970-01-01
  • 2015-10-18
相关资源
最近更新 更多