@extend with pseudo-class has unexpected priority
See original GitHub issueConsider the following scss
.foo:hover{
color:red;
}
.foo.bar.baz{
color:blue;
}
p.extended{
@extend .foo;
@extend .bar;
@extend .baz;
}
I would like p.extended elements to always have the blue color with no red :hover
state, since I am extending .foo
.bar
and .baz
which have a higher priority than just .foo:hover
However in the resulting css
.foo:hover, p.extended:hover {
color: red;
}
.foo.bar.baz, p.extended {
color: blue;
}
This means that p.extended
elements will still have the red :hover
state, but elements with class="foo bar baz"
will not.
I’m not sure if there is a way of fixing without getting really hacky this but suggestions welcome.
Issue Analytics
- State:
- Created 8 years ago
- Comments:6
Top Results From Across the Web
Sass extend with pseudo selectors - Stack Overflow
In fonts I have this rule which I would like to reuse @extend. //fonts.scss .icon-ab-logo, { font-family: 'icomoon'; speak: none; font-style: ...
Read more >Sass Style Guide | CSS-Tricks
Use Your Regular CSS Formatting Rules / Style Guide · List @extend(s) First · List @include(s) Next · List “Regular” Styles Next ·...
Read more >How to create your own ad filters - AdGuard Knowledgebase
AdGuard extends CSS and lets filters developers handle much more complicated cases. However, to use these extended rules, you need to be fluent...
Read more >Configuring Variants - Tailwind CSS
Targets the disabled pseudo-class. For more information about how variants work, read our documentation on responsive variants, dark mode variants, and hover, ...
Read more >Styling - Vanilla Extract
All the styling APIs in vanilla-extract take a style object as input. ... CSS properties can be set just like when writing a...
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
The
@extend
directive is working as expected here. Here’s the breakdown:@extend .foo;
:hover
, setcolor: blue
(from.foo:hover
).bar
and.baz
, setcolor: red
@extend .bar;
.foo
or matchesp.extended
(since that extended.foo
), and has a class of.baz
, setcolor: blue
@extend .baz
.foo
or matchesp.extended
, and has a class of.bar
or matchesp.extended
(since that extended.bar
), setcolor: blue
p.extended.foo.bar, p.extended.foo.baz, p.extended.bar.baz
selectors sincep.extended
extends.foo, .bar, .baz
You’re doing some complicated extending here. Try extending only
%placeholder
selectors:Or something similar. I do not know what you’re intending to do, or how you’re using this in real life, but hopefully the above example will help guide you.
Thanks David. My ‘real life’ example was trying to extend selectors from a third-party CSS that I’m using as if it was SCSS. I don’t want to have to change it by adding %placeholder selectors. I have another work-around that I can use.