How to implement `CSS` nested rules in `JSS`?

Santhan Frankenstein picture Santhan Frankenstein · Aug 2, 2018 · Viewed 10.5k times · Source

I would like know how to work with css class-nesting in Material-UI or in JSS in general?
I am trying as below.

    card: {
      cardHeader:{
         marginTop:"30px"
      }
    }

Answer

user2811588 picture user2811588 · Jan 12, 2020

For JSX like

<div className={classes.card}>
  <div className={classes.cardHeader}></div>
</div>

you can use:

card: {
  '& $cardHeader': {
      marginTop: 30,
  }
}

Targeting nested classes can be helpful if you override default JSS styles in Material UI components.