Create-react-app: Priority of importing styles

Created on 18 Dec 2017  路  4Comments  路  Source: facebook/create-react-app

Hey all, I ran into the same problem:

I have index.js which contains this code:
import React from 'react';
import { render } from 'react-dom';

import App from './App.js';
import 'bootstrap/dist/css/bootstrap.css';

render(
,
document.querySelector('#app')
);

In the component App.js
I have import a different style, for example
import './styles/button.css';

The problem is that in the final build of the css file, my button.css is before bootstrap.css

How can I change priority? Thanks in advance for the help

question

Most helpful comment

I solved this problem. To resolve this, you need to attach a stylesheet before you import the App component

All 4 comments

I solved this problem. To resolve this, you need to attach a stylesheet before you import the App component

@codefln Attach a stylesheet how? Do you mean add it to the index.html?

@bondz No, I used import styles in .jsx

Correct, css is ordered by the order they're imported (top-down). The imports happen depth-first, not breadth-first.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fson picture fson  路  3Comments

adrice727 picture adrice727  路  3Comments

stopachka picture stopachka  路  3Comments

rdamian3 picture rdamian3  路  3Comments

jnachtigall picture jnachtigall  路  3Comments