React style/css/sass order
up vote
0
down vote
favorite
I have my "App-component" and a "B-component" that gets rendered inside my app component. Each has its own style.
But when it gets compiled, my ComponentB.css is put before my app.css, making the ComponentB styles being overwritten by my app styles.
Why is this happening??
APP
import React, Component from 'react';
import ComponentB from './components/ComponentB';
import './styles/app.css';
class App extends Component
render()
return (
<div className="App">
<ComponentB />
</div>
);
export default App;
COMPONENT B
import React, Component from 'react';
import './styles/ComponentB.css';
class ComponentB extends Component
render()
return (
<div>
<h1>Hello from ComponentB</h1>
</div>
);
export default ComponentB;
css reactjs sass order styles
add a comment |
up vote
0
down vote
favorite
I have my "App-component" and a "B-component" that gets rendered inside my app component. Each has its own style.
But when it gets compiled, my ComponentB.css is put before my app.css, making the ComponentB styles being overwritten by my app styles.
Why is this happening??
APP
import React, Component from 'react';
import ComponentB from './components/ComponentB';
import './styles/app.css';
class App extends Component
render()
return (
<div className="App">
<ComponentB />
</div>
);
export default App;
COMPONENT B
import React, Component from 'react';
import './styles/ComponentB.css';
class ComponentB extends Component
render()
return (
<div>
<h1>Hello from ComponentB</h1>
</div>
);
export default ComponentB;
css reactjs sass order styles
For example my normalize css its import in my app.css but in the compilation my componentB.css it put before my app.css.
– Maria
Nov 11 at 11:53
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have my "App-component" and a "B-component" that gets rendered inside my app component. Each has its own style.
But when it gets compiled, my ComponentB.css is put before my app.css, making the ComponentB styles being overwritten by my app styles.
Why is this happening??
APP
import React, Component from 'react';
import ComponentB from './components/ComponentB';
import './styles/app.css';
class App extends Component
render()
return (
<div className="App">
<ComponentB />
</div>
);
export default App;
COMPONENT B
import React, Component from 'react';
import './styles/ComponentB.css';
class ComponentB extends Component
render()
return (
<div>
<h1>Hello from ComponentB</h1>
</div>
);
export default ComponentB;
css reactjs sass order styles
I have my "App-component" and a "B-component" that gets rendered inside my app component. Each has its own style.
But when it gets compiled, my ComponentB.css is put before my app.css, making the ComponentB styles being overwritten by my app styles.
Why is this happening??
APP
import React, Component from 'react';
import ComponentB from './components/ComponentB';
import './styles/app.css';
class App extends Component
render()
return (
<div className="App">
<ComponentB />
</div>
);
export default App;
COMPONENT B
import React, Component from 'react';
import './styles/ComponentB.css';
class ComponentB extends Component
render()
return (
<div>
<h1>Hello from ComponentB</h1>
</div>
);
export default ComponentB;
css reactjs sass order styles
css reactjs sass order styles
edited Nov 11 at 12:32
Stundji
356211
356211
asked Nov 11 at 10:24
Maria
1
1
For example my normalize css its import in my app.css but in the compilation my componentB.css it put before my app.css.
– Maria
Nov 11 at 11:53
add a comment |
For example my normalize css its import in my app.css but in the compilation my componentB.css it put before my app.css.
– Maria
Nov 11 at 11:53
For example my normalize css its import in my app.css but in the compilation my componentB.css it put before my app.css.
– Maria
Nov 11 at 11:53
For example my normalize css its import in my app.css but in the compilation my componentB.css it put before my app.css.
– Maria
Nov 11 at 11:53
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
The way you do it results in a styles conflicts(one style overwriting another style), because after React compiles your code you are still using the same selectors for the same classes.
If you want to use different css files for different components while using the same class names, you should use CSS modules.
This will make your CSS class names scoped locally by default.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
The way you do it results in a styles conflicts(one style overwriting another style), because after React compiles your code you are still using the same selectors for the same classes.
If you want to use different css files for different components while using the same class names, you should use CSS modules.
This will make your CSS class names scoped locally by default.
add a comment |
up vote
0
down vote
The way you do it results in a styles conflicts(one style overwriting another style), because after React compiles your code you are still using the same selectors for the same classes.
If you want to use different css files for different components while using the same class names, you should use CSS modules.
This will make your CSS class names scoped locally by default.
add a comment |
up vote
0
down vote
up vote
0
down vote
The way you do it results in a styles conflicts(one style overwriting another style), because after React compiles your code you are still using the same selectors for the same classes.
If you want to use different css files for different components while using the same class names, you should use CSS modules.
This will make your CSS class names scoped locally by default.
The way you do it results in a styles conflicts(one style overwriting another style), because after React compiles your code you are still using the same selectors for the same classes.
If you want to use different css files for different components while using the same class names, you should use CSS modules.
This will make your CSS class names scoped locally by default.
answered Nov 11 at 10:40
Stundji
356211
356211
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247806%2freact-style-css-sass-order%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
For example my normalize css its import in my app.css but in the compilation my componentB.css it put before my app.css.
– Maria
Nov 11 at 11:53