A common problem I have with @extend
is when trying to override the inherited properties with another @extend
.
Here's an example:
// class selectors to be @extended
// these could also use % to be silent/placeholder selectors
.size-2xl {
@include rem(font-size, 40px);
}
.size-3xl {
@include rem(font-size, 60px);
}
// mapping the class selector properties onto some structural classes
.heading1 {
@extend .size-3xl;
}
.heading1-small {
@extend .heading1;
@extend .size-2xl;
}
When the SCSS is compiled, .heading1
and .heading1-small
will get the correct properties, but .heading1-small
will appear too large.
This seems to occur when the @extend
-able class is mapped onto a few different selectors.
When the SCSS is compiled to CSS, the various selectors are combined into one or more rule sets with multiple selectors.
Sometimes the SCSS appears to be compiled 'out of order', so that the compiled .heading1
multiple selector is output after the .heading1-small
multiple selector.
It could even be the nested @extend
causing this behaviour.
What is the best way to avoid this situation? Some things I can think of off the top of my head are:
- use
@include('size-2xl')
(less DRY) - don't
@extend
rules containing@extend
(limits the use of @extend)
Thanks.