How to nest classes in css modules and react?

Tags: reactjs,css-modules

Problem :

I am trying to use CSS Modules in my React project. First part of the problem is that if I write nested css classes (using sass), I don't know if I can access the inner ones, since those seems to be compiled into unique classnames as well. Some code:

<div className={this.state.visible ? styles.header+" menu-visible" : styles.header}>
    <div className="menu">
        <a className="link">title</a>

   .header {
       &.menu-visible {
            .menu {

I have a wrapping class that sometimes is "menu-visible" which changes attributes on all the children, is it bad practice to do it like this in React?

There is multiple classes inside the .header that are changed if the menu is visible, therefore it would be convinient to just change the wrapping class, can I reference the children in some way? So that the remain nested in scss?


One solution that I can think of is to replace className="menu" with className={} but that seemed not to work. The problem is that I would like .menu to change its attributes if its parent has the class menu-visible.

Solution :

Ok, I solved it. I think that I just overdid it in my mind. Instead of writing I could just write, even if it was nested...

    CSS Howto..

    How to stop loading pdf on mobile device?

    How to force enter key to make a line break inside iframe editor

    jQuery: How can I set css with own width?

    how to dynamically change the property of css using jquery

    How can I align my HTML components with CSS?

    How to remove the “Facebook social plugin” text?

    Python: How to override text area in form using CSS

    CSS Flexbox: how to change the width of the element

    Both DIV Popups Shown Instead of One

    How to add strped tabs on Ionic css

    how to make body tag elastic?

    how to trigger a stored property with css color change?

    How to make pure css floating tooltips (absolutely positioned span) dynamically resize to accommodate text

    How do I style just the thumbnail image in this post?

    How can I add spaces between two lines using CSS?

    How to add ::after in the HTML link tag

    How to adjust CSS to display correctly in IE 6?

    How to find the css, color codes and other coding a site uses

    How to Reset CSS after Media Query?

    How do I update an div css to display an complete image when section is complete?

    How to contain a div floating outside of container div

    How do I make a play button for my full page video?

    How to have different table styles in CSS

    How can I stop this ugly font smoothing with custom fonts in CSS?

    How to hide sliding div with css

    How to use jQuery to horizontally center an object in the viewport?

    How to restrict the contents in a table data() of a table to a certain limit?

    How to add border to a container with transparent gaps in between

    How to get all child elements using an xpath selector?

    How can I put styleName (css) on ui.xml to HTML5 input element (range)