When you write
.a .b .c .d {
color: blue;
}
What you're saying is
Any element with class
d
that's nested beneath elements with classesa
,b
, andc
in that order should have blue text.
Then when you write
.e .f .g .h {
@extend .d;
}
what you're saying is
Any element with class
h
that's nested beneath elements with classese
,f
, andg
in that order should be styled as though it also has classd
.
The conjunction of these two statements implies
And element with class
h
that's nested beneath elements with classese
,f
, andg
in that order and beneath elements with classesa
,b
, andc
in that order should have blue text.
It's important to note that the two nesting requirements here don't have any particular order. Both of the following spans should have blue text:
<div class="a">
<div class="b">
<div class="c">
<div class="e">
<div class="f">
<div class="g">
<span class="h">Order 1</span>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="e">
<div class="f">
<div class="g">
<div class="a">
<div class="b">
<div class="c">
<span class="h">Order 1</span>
</div>
</div>
</div>
</div>
</div>
</div>
The way to represent this in CSS is
.a .b .c .d, .a .b .c .e .f .g .h, .e .f .g .a .b .c .h {
x: y; }
Note that fully satisfying those semantics would produce exponential output, so Sass elides all but the two most likely permutations for space reasons.
Thanks for expressing this so clearly. I agree that this makes sense as a safeguard for possible styling, but I'm concerned that it's excessively defensive. There are conflicting use cases:
I realize for the second case there's already an established best practice to extend only placeholder selectors, but I'm trying to determine if there's a way to chip away at the "third rail" qualities of extend, making it safer to use in both cases.
It's much easier to explain extending A from B gives you a new selector with A replaced by the selector B than extending A from B tries a handful of strategies to make sure everyplace you were using A you can now use B. The second is pretty cool, but it's hard to reason around what is actually happening.
(I say "a handful of strategies" because there's also the behavior of https://gist.github.com/anonymous/aacad2e475e212450f26 .)
We're doing a lot to try to protect the user from the effects of their intentions, while it may be preferable to allow simpler logic to do the wrong thing predictably, empowering users to better protect themselves.