Shorten multiple elements with the same class in Sass

The Sass, you can write .class1 .class2 {}

, and .class1 .class3 {}

as,

.class1 {
 &.class2, &.class3 {}
}

      

How do you cut

div.class1,
h2.class1,
p.class1 {}

      

This doesn't work as expected,

.class1 {
 & div, & h2, & p {}
}

      

+3


source to share


1 answer


You have the right idea, you just made a small mistake in your shortcut. Remove the space between the &

and element and nest the class .class1

instead of the individual elements.



div, h2, p {
    &.class1 {}
}

      

+3


source







All Articles