question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Css available even if not imported

See original GitHub issue

Hi, I have an issue where once I import a css file the classes are known throughout the app. e.g:

in LoginContainer I have: import './login.css';<div className="container">//html here</div> and in ForgotPasswordContainer: import './forgotPassword.css';<div className="container">//html here</div> both have a different class for container and are imported by different files. But I keep getting only a single occurrence meaning if I change one container class then html changes for both.

this doesnt allow me to override. Im used to working with Angular and scss so Im new to the importing css classes so Im not sure if this is how its supposed to work. But the way it is now for me importing classes doesnt make sense since they are global for the entire project.

as far as changes to the create-react-app boilerplate, I have only introduced the node-sass change which doesnt effect any of this code since I watch different folders

can anyone assist?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
gaearoncommented, Dec 16, 2016

I wish there was a better way to solve this.

I’m just not comfortable enabling CSS Modules by default because:

  • It uses custom syntax extensions to CSS and breaks some tooling.
  • It is local by default and people unfamiliar with this paradigm will file hundreds of issues about CSS “not working”.
  • This space is rapidly changing and I don’t want to embrace a potential dead end solution.

If there is a clear winner in the “local CSS” space that community fully embraces I’d be happy to go with it but it’s not the case today.

2reactions
tbillingtoncommented, Dec 16, 2016

@Jony-Y I don’t want to be rude but it might help if you had a better understanding of how css works. There’s no way possible right now to do anything like what you’re asking with css.

However, there are libraries that link styles to the react component by writing the css in the javascript then it autogenerates custom css names or sets the styles on the html elements themselves so they never clash. Something like this https://github.com/styled-components/styled-components.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS getting applied to all files even though not imported
I import the respective CSS files within each js file, but the a styling in footer.module.css seems to overtake the styling in header.js...
Read more >
Solving the React Error: Not Picking Up CSS Style | Pluralsight
CSS helps in styling webpages, but sometimes code may not get properly imported or may show a few errors while it is being...
Read more >
CSS @import Rule - W3Schools
The @import rule allows you to import a style sheet into another style sheet. The @import rule must be at the top of...
Read more >
Using CSS Module Scripts to import stylesheets - web.dev
Learn how to use CSS module scripts to import CSS stylesheets using the same syntax as JavaScript modules.
Read more >
import - CSS: Cascading Style Sheets - MDN Web Docs
The @import CSS at-rule is used to import style rules from other valid stylesheets. An @import rule must be defined at the top...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found