Live data from Hacker News

Do We Need Specificity in CSS? (2015)

philipwalton.com

1–10 of 53 posts

Re: Do We Need Specificity in CSS? (2015)

#3
The simple solution is delete before you add more specificity. Cut it back to the common denominator and cascade from there.

Of course, you can sometimes inherit a system that is one big specificity mess.

Re: Do We Need Specificity in CSS? (2015)

#4
While this is an interesting thought experiment, and the outlined problem is a real issue, I don't think the outlined solution is a good way to resolve it. The main problem here is predictability: maybe it's simply that I'm not used to thinking about CSS this way, but the proposed CSS rewriting parser means it's not immediately obvious how what I write maps to the end result.

It's entirely possible that I'm missing some of the benefit here, but it seems to me that scoped styles etc largely already solve this problem.

Re: Do We Need Specificity in CSS? (2015)

#6
I always write the specificity in the same order as the cascade. Could probably write a tool that compares the specificity vs the cascade to find errors!

There is however a small problem if you want to use many CSS files - that you need to link them in the correct order.

edit: Also I don't use ID's in CSS.

Re: Do We Need Specificity in CSS? (2015)

#9
In my experience, very, very few Web designers actually use specificity (UPDATE: I should have added "properly," as was pointed out).

It works extremely well, if everyone follows the rules, which is uncommon.

That goes for most of CSS; not just specificity.

CSS is incredibly powerful, if used properly, and specificity, when actually used properly, is very cool.

About ten years ago, I wrote this series: https://littlegreenviper.com/miscellany/stylist/introduction...

It’s still absolutely relevant nowadays, and just as few people follow that workflow now, as they did then.

CSS, in general, is too complicated (IMNSHO), but that complexity is also what makes it so powerful.

I’ve always enjoyed Stu Nicholls’ CSSPlay site, for examples of extreme CSS: http://www.cssplay.co.uk/menu/

Re: Do We Need Specificity in CSS? (2015)

#10
post #5

Warnings seem like the way to go for this? i.e. having a static analyzer to check that the specificity matches the declaration order. (Assuming that's possible... it's not obvious to me if there are theoretical roadblocks.)

Stylelint actually has this already! https://stylelint.io/user-guide/rules/no-descending-specific...
Post reply on HN