CSS Modules & ReactJS: Parent and child CSS classes in different components

Chase James picture Chase James · Feb 12, 2017 · Viewed 10k times · Source

So I am building a react application and have a quick question. If I have two separate components: and with CSS classes navigation.css and navigationLogo.css respectively. In navigation.css I have a class named .main and in navigationLogo.css I want to have a class like so:

.main .main_in_logo {
 color: red;
}

But with CSS Modules I am unable to do this, any ideas on a work around?

Answer

Dmitriy Kovalenko picture Dmitriy Kovalenko · Feb 12, 2017

Why you need to create .main .main_in_logo - the main idea of styles with parent elements its not to broke your css with other styles in the future. But its impossible with css modules, because your styles will be unique forever.

But even you really need it you can use global css for these 2 components - documentation about global css for react-css-modules.