Live data from Hacker News

Do We Need Specificity in CSS? (2015)

philipwalton.com

51–53 of 53 posts

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

#51

I feel like this article is just another: "CSS is hard, and instead of learning, use this clever method that works for me." Maybe I'm just old school because I learned CSS2 by reading the docs, and not as CSS in JS.

Not only approaching the "problem" of learning CSS by eliminating things to learn, but starting from bad assumptions (e.g. that combining stylesheets is a problem and not a solution) and never questioning them.

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

#52

Earlier quoted context omitted.

why? custom.css would still be loaded, just that if any rules conflict between the two, the original stylesheet would win. if custom.css makes some text bold and red, and then a second stylesheet comes along and makes the text blue, the final text would be bold and blue. but with CSS specificity defining priority, whether the text is blue or red depends on which file has the gnarliest, most complicated selector. cust…

Ah, thanks for the explanation -- I thought that you meant that custom.css would be disregarded, now I see you meant that css _rules_ should use "last declaration wins". Not really a followup on my previous question: what would be done if, say one can't change the order: so custom.css is still before original css. In such cases, without the specificity rule, wouldn't the only option we'd have is to somehow inline the…

that's true, but that's pretty much the experience of writing userstyles anyway. i remember back in the greasemonkey days, their built-in editor even had an option to automatically append `!important` to every line when you click save.

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

#53

Earlier quoted context omitted.

BEM I think comes from choice to aggressively reduce complexity, not from ignorance. Sprinkled with a tiny bit of specificity classes for state, it combines best of both worlds.

then why is BEM more complex than just plain CSS? if the idea is to reduce complexity, that’s a giant fail.

It is less complex in that it eliminates specificity conflicts and approaches CSS in a modular fashion by namespacing each module/block.

You have to name things, then you don't have to apply multiple rules.

Post reply on HN