4 ms·
> avoid !important Sure, haven't seen that in a while in well structured code bases. > make everything the same specificity How would you achieve same specif
by lavela 3y ago
> avoid !important
Sure, haven't seen that in a while in well structured code bases.
> make everything the same specificity
How would you achieve same specificity on everything? Only use either ids or classes? No type selectors / pseudo-classes / pseudo-elements / multiple selectors? I can't imagine how that would be feasible and am not aware of anyone recommending this.
- Supermancho 3y agoThere are a large number of companies that require ids as the basis for every selector, by policy. This may not be interesting to you, but I think this is what they meant. The fact they may or may not be familiar to you is incidental.
- lavela 3y agoI'm familiar with policies that generally strive for specificity of (0, 1, 0) like BEM or (1, 0, 0), but I'd be very interested in any policy that rules out pseudo-classes like `:hover`, as prohibiting them would leave you to handle any interactivity you'd get for free from CSS via JavaScript.
- blowski 3y agoThis is effectively how Tailwind works. You end up with classes like `hover:text-black`.
- afiori 3y agoWith :is and :where it is trivial to trick selectors :is(selector_1, :where(selector_2)) Has always the specificity of selector_2, and if you choose an impossible selector for selector_1 (the easiest approach is to give multiple ids or use non existent classes/elements) it only select by selector_2
- oneeyedpigeon 3y agoThat looks far more complex than just using specificity properly as intended.