正在加载视频...

视频加载失败

How to use the :where CSS selector to solve specificity problems ↓

61,881 次观看 • 1 年前 •via X (Twitter)

10 条评论

Sebastiano Guerriero 的头像
Sebastiano Guerriero1 年前

As a general rule, I try to keep CSS selector specificity low. It simplifies code maintenance. In this example, you might use: '.cd-calendar-date:hover:not(.cd-calendar-date--selected) {}' to achieve the same result, but it creates high specificity, leading to potential override issues. The :where selector is handy because it lowers the specificity.

Shay Punter 的头像
Shay Punter1 年前

Honestly the :where operator is such an underrated operator, I am surprised that more people aren't using it. Lets you be very specific in terms of what you can style, very useful for use-cases like above!

Sebastiano Guerriero 的头像
Sebastiano Guerriero1 年前

💯

Alireza Bashiri 的头像
Alireza Bashiri1 年前

you're saving an entire generation from @tailwindcss

Oath 的头像
Oath1 年前

smart way of using :where, thanks for the tip

Alex K 的头像
Alex K1 年前

Great advice

ƨergey 的头像
ƨergey1 年前

Nice but hard to support, unless you comment this shit 😀 Prefer to have .active class

Sebastiano Guerriero 的头像
Sebastiano Guerriero1 年前

You’d still need the .active class (.cd-calendar-date—selected in this example). The :where operator only saves you some code because you wouldn’t need to override .class:hover with .active:hover

Eric Fortis 的头像
Eric Fortis1 年前

I rather .cd-calendar-date--selected, .cd-calendar-date--selected:hover {}

Sebastiano Guerriero 的头像
Sebastiano Guerriero1 年前

You can do that, but you’d need to override the .cd-calendar-date:hover style.

相关视频