parm530
4/19/2018 - 5:31 PM

SASS '&' Operator

What is and how to use the '&' operator in SASS

What is the & operator in SASS?

  • Equivalent to nesting
  • When you need more specific selector: for when you want to select an element that has 2 classes, but also be more specific at the same time:
// plain css:
.some-class.another-class {}

// in SASS
.some-class {
  &.another.class {}
}

  • Theyre both ways to select an element with one class and select a more specific element with another class!
  • You can also use & when nesting parent and child elements:
// in SASS
.parent {
  .child {}
}

// can also be written as:
.parent {
  & .child {}
  // notice the space after the ampersand!!!
}