Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overriding bootstrap styles #1611

Closed
joewoodhouse opened this issue Feb 22, 2017 · 8 comments
Closed

Overriding bootstrap styles #1611

joewoodhouse opened this issue Feb 22, 2017 · 8 comments

Comments

@joewoodhouse
Copy link
Contributor

Hi guys,

This is probably a very stupid question, but ...

I've imported bootstrap into my create-react-app project as per the documentation (very nice).

However when I look at the generated markup, all the <style> tags for my components e.g. Header.css come before the bootstrap css, which means I can't (easily) override bootstraps default styling.

Is there a way to ensure bootstrap gets put before other css files?

@viankakrisna
Copy link
Contributor

Can you provide the snippets of your index.js (especially the import section)?

@joewoodhouse
Copy link
Contributor Author

My index.js is simply:

import React from 'react';
import ReactDOM from 'react-dom';
import { browserHistory } from 'react-router';

import Routes from './routes';

import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap/dist/css/bootstrap-theme.css';

import './index.css';

ReactDOM.render(
  <Routes history={browserHistory} />,
  document.getElementById('root')
);

@viankakrisna
Copy link
Contributor

try to move the css imports above import Routes from './routes'; I think that's because style-loader reads the css imported from components in Routes first rather than bootstrap. like this

import React from 'react';
import ReactDOM from 'react-dom';
import { browserHistory } from 'react-router';

import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap/dist/css/bootstrap-theme.css';

import './index.css';

import Routes from './routes';

ReactDOM.render(
  <Routes history={browserHistory} />,
  document.getElementById('root')
);

And see if it works

@joewoodhouse
Copy link
Contributor Author

Yes that does work, thanks very much! I wonder if that might be worth adding to the "Add Bootstrap" section of the docs, as it's not made clear there.

@viankakrisna
Copy link
Contributor

PR?

@Timer
Copy link
Contributor

Timer commented Feb 22, 2017

@joewoodhouse if you could add a note about this to the Adding Bootstrap section, that would be great!

@grundmanise
Copy link

This is what worked for me:

import './index.css'
import 'bootstrap/dist/css/bootstrap.css';

import React from 'react';
import ReactDOM from 'react-dom'
import Routes from './app/routes'


ReactDOM.render(
  <Routes />,
  document.getElementById('root')
);

@jaredgalanis
Copy link

For some reason this is not working for me. The index.js file does look different at this point. There's no import of Routes.

import 'bootstrap/dist/css/bootstrap.css';

import './index.css';
import './SelectOption.css';

import React from 'react';
import ReactDOM from 'react-dom';

import PlayerContainer from './PlayerContainer';
import registerServiceWorker from './registerServiceWorker';

ReactDOM.render(<PlayerContainer />, document.getElementById('root'));
registerServiceWorker();

@lock lock bot locked and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants