Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
Why css-files in react-create-app have exactly this sequence?

index.css file in react-create-app added to <head> as the last <style> elemnt. As I understand it, this is because mounting is a Recursive Process. Because index.css is at the bottom, its styles take precedence. It confused me. According to my logic if I want to use .title {font-family: Roboto; font-size: 2.5rem} for all titles in my app, I will write this in index.css. But when I want to use other typeface for title in my <Article /> component saving font-size I will write mixin .article__title {font-family: Tahoma} in Article.css file. But it doesn't give the result I want. And the font-family won't be overwritten, because .title takes precedence over .article__title. Where and how should I use common styles that I can rewrite in components?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

CSS cascading in React will be the same as if you were working with vanilla HTML -- at the same precedence level, the last rule to be defined wins.

...which can be fragile, so just like in plain HTML+CSS it's usually better and more maintainable to make your CSS rules have greater or lesser specificity, instead of depending on the order in which they appear.

For your example where you have .title taking precedence over .article__title (I assume because both classNames are on the same DOM element, and .title happens to be defined later), instead of trying to change the order of the CSS rules, change their specificity:

.title {/* default rules */}
.title.article__title {/* override rules */}

That will have the same results regardless of the order in which the selectors appear in your CSS files. (You can do the same using parent nodes instead -- a very common strategy in React is to have one set of global CSS rules, and then set specific additional classnames on the root level of each of your components which can override those global rules.

Or as a last resort, there's always !important. (But don't use !important, you'll just wind up with the same specificity problem later on but worse.)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!