【问题标题】:Can't get Boostrap CSS to load in a React App无法让 Bootstrap CSS 加载到 React 应用程序中
【发布时间】:2016-12-21 00:15:34
【问题描述】:

这是我的 HTML 文件:

<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <link rel="stylesheet" href="{{ url_for('static',filename='styles/bootstrap.min.css') }}">
        <link rel="stylesheet" type="text/css" href= "{{ url_for('static',filename='styles/style.css') }}">
        <script src="https://npmcdn.com/react@15.3.0/dist/react.js"></script>
        <script src="https://npmcdn.com/react-dom@15.3.0/dist/react-dom.js"></script>
        <script src="https://npmcdn.com/babel-core@5.8.38/browser.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/react-bootstrap/0.30.7/react-bootstrap.js"></script>
        <meta charset="utf-8">
        <title>Dashboard</title>

    </head>
    <body>
        <div id="content"></div>
        <script type="text/babel" src="/static/js/dashboard.js"></script>
    </body>
</html>

文件位于:

/Simple_flask_app
 -hello.py

  /static
    -js

  /styles
    -boostrap.min.css
    -style.css

我创建了一个简单的组件来尝试加载 CSS:

var Dashboard = React.createClass({
    render: function(){
         return (
             <div>
                 <div class="jumbotron">
                     <h1>Test</h1>
                 </div>
              </div>
             )

ReactDOM.render(<Dashboard />, document.getElementById('content'));

我试图加载这个巨大的灰色盒子 - https://getbootstrap.com/examples/navbar/

因为我在 React 中,所以我必须做一些特别的事情吗?

【问题讨论】:

    标签: html css reactjs


    【解决方案1】:

    在 React 的 JSX 中,您必须使用 'className' 而不是 'class'。

    所以你应该把&lt;div class="jumbotron"&gt;改成&lt;div className="jumbotron"&gt;

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-12
    • 2020-06-17
    相关资源
    最近更新 更多