Video wird geladen...

Video konnte nicht geladen werden

Zur Startseite

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

61,881 Aufrufe • vor 1 Jahr •via X (Twitter)

10 Kommentare

Profilbild von Sebastiano Guerriero
Sebastiano Guerrierovor 1 Jahr

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.

Profilbild von Shay Punter
Shay Puntervor 1 Jahr

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!

Profilbild von Sebastiano Guerriero
Sebastiano Guerrierovor 1 Jahr

💯

Profilbild von Alireza Bashiri
Alireza Bashirivor 1 Jahr

you're saving an entire generation from @tailwindcss

Profilbild von Oath
Oathvor 1 Jahr

smart way of using :where, thanks for the tip

Profilbild von Alex K
Alex Kvor 1 Jahr

Great advice

Profilbild von ƨergey
ƨergeyvor 1 Jahr

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

Profilbild von Sebastiano Guerriero
Sebastiano Guerrierovor 1 Jahr

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

Profilbild von Eric Fortis
Eric Fortisvor 1 Jahr

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

Profilbild von Sebastiano Guerriero
Sebastiano Guerrierovor 1 Jahr

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

Ähnliche Videos