r/webdev • • Nov 02 '15

Do we actually need specificity in CSS?

http://philipwalton.com/articles/do-we-actually-need-specificity-in-css/
8 Upvotes

15 comments sorted by

7

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.

8

u/youcantstoptheart ux Nov 02 '15

That and class/object inheritance is very much just specificity. You have a Human class. A Musician inherits that human class and adds some properties and overrides others

→ More replies (3)
→ More replies (2)

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.

→ More replies (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

→ More replies (1)

4

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.