3 ms·
>Selectors are evaluated by a specificity score. This is where most of the 'logic' breaks down for me. The specificity scoring is a system of weights that trip
by wildrhythms 3y ago
>Selectors are evaluated by a specificity score.
This is where most of the 'logic' breaks down for me. The specificity scoring is a system of weights that trips up a lot of new front end developers. It's not straightforward. Different selectors have different weights you need to know about. There are 'hacks' you need to know about when you find yourself needing to override particularly heavy selectors. https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity
And conveniently the author doesn't mention !important.
I think nowadays I find myself using CSS variables and calc() more often to establish some system of logic in my CSS. I can have --spacing: 120% variable at the root of the tree, and all its descendants can consume that and use calc() to multiply that by a unit value to have consistently scaled spacing. The author doesn't mention this, but it's great!
- dsego 3y agoWhat's more logical than writing `.myClass.myClass.myClass` to overpower a more specific selector. Add in a `div.myClass.myClass.myClass` for good measure.
- tauchunfall 3y ago>It's not straightforward. Yeah, it's a bit implicit. Or you have to learn the rules by heart. I also saw people struggle with two elements aligned to bottom with different line heights. Turned out they did not know that there is a default line height. And of course the "correct" line height to use is either "1" or "1.15" (not the browser default).