Skip navigation
How to use the :where CSS selector to solve specificity problems ↓
0:00 / 0:24

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

Sebastiano Guerriero

@guerriero_se19K followers

Visit on X
805 likesDownloadOriginal post

61,982 views

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

10 Comments

Comments from the original post on X (Twitter)

  • Sebastiano Guerriero's profile picture

    @guerriero_se

    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.

    9 likes

  • Shay Punter's profile picture

    @ShayPunter

    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!

    2 likes

  • Sebastiano Guerriero's profile picture

    @guerriero_se

    💯

  • Alireza Bashiri's profile picture

    @al3rez

    you're saving an entire generation from @tailwindcss

    1 like

  • Oath's profile picture

    @othmaneBks

    smart way of using :where, thanks for the tip

    1 like

  • Alex K's profile picture

    @uialexk

    Great advice

    1 like

  • ƨergey's profile picture

    @0xbdrtsky

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

  • Sebastiano Guerriero's profile picture

    @guerriero_se

    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

    1 like

  • Eric Fortis's profile picture

    @efortis

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

  • Sebastiano Guerriero's profile picture

    @guerriero_se

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