Extending a compound selector violates extend semantics
See original GitHub issueCurrently, when a compound selector is extended, Sass will only replace instances of the full extendee with the extender. For example:
.a {x: y}
.b {x: y}
.a.b {x: y}
.c {@extend .a.b}
produces
.a {x: y}
.b {x: y}
.a.b, .c {x: y}
when it should produce
.a, .c {x: y}
.b, .c {x: y}
.a.b, .c {x: y}
according to the semantics of @extend
. We should fix this, especially as CSS moves closer to supporting @extend
natively.
Tasks:
- Deprecate existing behavior in
stable
. - Remove behavior from
master
.
Issue Analytics
- State:
- Created 9 years ago
- Reactions:25
- Comments:95 (20 by maintainers)
Top Results From Across the Web
Breaking Change: Extending Compound Selectors - Sass
When one selector extends another, Sass styles all elements that match the extender as though they also match the class being extended.
Read more >Selectors Level 4 - W3C
Prepending another compound selector and a combinator to a sequence imposes additional matching constraints, such that the subjects of a complex ...
Read more >Extending In Sass Without Creating A Mess
The @extend directive in Sass is a powerful directive that facilitates the sharing of rules and relationships between selectors.
Read more >Redex: Practical Semantics Engineering
The tutorial works though a model of the λ-calculus extended with ... The compound rewriter is given a list of lw structs that...
Read more >HTML Standard
The defining instance of an element, attribute, or API is marked up like this . ... In order to allow the language syntax...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I still miss the logic why
.a.b.
also matches.a
and.b
individually. Those are 3 different selectors, it just so happens that they consist from same elements, but nothing more.It just goes against CSS logic, since when in CSS we write more complex selectors, we increasing its specificity on purpose, to ensure that only “those instances of class” with
class='a b'
will receive that style, notclass='a'
andclass='b'
.I think Sass can follow pretty much close same logic — when you increase specificity of extend, you want to extend only specific selectors, not everything related to them, otherwise you would write more generic extend.
-1 to this. If I want .c to extend .a and .b I write
.c { @extend .a; @extend .b; }
.