0

I'm new to sass and looking for the syntax to specify a hierarchical relationship with code in the child class definition.

Currently I have:

.my-option
  color: #7E57EE

I'd like my sass to compile to the following CSS:

.my-option
  color: #7E57EE

.is-active .my-option
  background-color: #BADA55

I know two ways to accomplish this:

//More verbose than I'd like (and just plain css...)     
.my-option
  color: #7E57EE

.is-active .my-option
  background-color: #BADA55

//Too generic because...don't want the is-active definition to be cluttered
.my-option
  color: #7E57EE

.is-active
  .my-option
    background-color: #BADA55
Steven Wexler
  • 16,589
  • 8
  • 53
  • 80

1 Answers1

1

You can use & at the end of the contextual selector, which will put your child class there for you:

.my-option
  color: #7E57EE

  .is-active &
    background-color: #BADA55

Since you're writing Sass, be sure to indent the second rule so that the compiler will interpret it correctly.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356