Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-bootstrap contains no css

my jsx file successfully recognizes the react-bootstrap elements but there's no styling to them. my project's node-modules folder contains both react-bootstrap and bootstrap. why is this happening?

var React = require('react');
var Button = require('react-bootstrap').Button;
var Jumbotron = require('react-bootstrap').Jumbotron;

var ReactComponentHi = React.createClass({displayName: 'Hi',

    render: function() {
        return (
            <div>
                <Button bsStyle='success'>
                    clickk
                </Button>
                <Jumbotron>
                    <h1>Hello, world!</h1>
                    <p>This is a simple hero unit, a simple jumbotron-style component for calling extra attention to featured content or information.</p>
                    <p><Button bsStyle='primary'>Learn more</Button></p>
                </Jumbotron>
            </div>

        );
    }
});

module.exports = ReactComponentHi;

what the results look like

like image 320
Simon Avatar asked Aug 26 '15 14:08

Simon


People also ask

How to use Bootstrap with react?

How to Use Bootstrap with React? 1 1. Using Bootstrap CDN. This is one of the easiest ways to use bootstrap in your React app. The best thing about bootstrap CDN is no requirement for ... 2 2. Import Bootstrap as a Dependency. 3 3. Install React Bootstrap Package.

How to override the table element in react-bootstrap?

With react-bootstrap, the table element can be overridden using the custom CSS classes, but before using the table, you need to import it. After importing the table element and bootstrap CSS, create the basic table. In the above render () function, <Table> elements uses the header and body section along with the combination of rows and columns.

Why doesn't my bootstrap work with Webpack?

If it doesn't, most probably the issue is that you haven't set your webpack to use a CSS loader. If you've installed the CSS just for your particular project, you can access it (by putting the following in index.js): import '../node_modules/bootstrap/dist/css/bootstrap.min.css';

How to add JavaScript components to bootstrap page?

In case your application needs JavaScript components along with the bootstrap, then at the bottom of the page place <script> tag, just before the closing </body> tag. These snippets will be added to the public/index.html page.


2 Answers

i added the following line to my index.html and it worked.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
like image 177
Simon Avatar answered Oct 07 '22 05:10

Simon


Actually, importing directly from the CDN is not needed, it's better to import the css from your local dist folder, to ensure the versions are the same.

Add this to your index.js / index.tsx below your other imports:

import 'bootstrap/dist/css/bootstrap.min.css';
like image 24
Kevin R Avatar answered Oct 07 '22 04:10

Kevin R