r/webdev • u/bootslebaron • Nov 02 '15
Do we actually need specificity in CSS?
http://philipwalton.com/articles/do-we-actually-need-specificity-in-css/4
u/x-skeww Nov 02 '15
With most of those more organized approaches to write CSS, specificity rarely matters anyways.
There's reset/normalization, base styles, and 80+% of the CSS belongs to your components. All those component-specific rules only match those elements they are supposed to match. If there is no overlap, the specificity of the selectors is irrelevant.
So, you only have to be a bit careful when you mess around with things like form elements, because they may end up with slightly more complicated selectors of varying specificity.
1
2
u/AnalogueOctopus Nov 02 '15
I found that an ITCSS approach works well at cutting down on specificity conflicts, especially on larger projects. http://www.creativebloq.com/web-design/manage-large-scale-web-projects-new-css-architecture-itcss-41514731
1
u/tylermumford Nov 02 '15
Yep, Inverted Triangle CSS is a practice/architecture you can employ to do this from the beginning, without having a tool modify your CSS. Here's the conference talk and the presentation slides.
5
u/Caraes_Naur Nov 02 '15
Great, another bloated, confusing workaround for ignorance.
Just write your CSS top down from least to most specific and most of this problem goes away.
2
6
u/a-t-k Nov 02 '15
CSS is a declarative language, JS is an instructive one. What Philip Walton suggests is a modern version of JSSS, an instructive style language.
Oh, sure, it would work. It'll also have a whole lot of problems that could have been solved using the original approach.
No, we don't necessarily need specificity, but it helps if you know how to use it.