Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Understanding the cascade, general experience with building many varied sites, and hard work



And that more specific rules override the cascade. And once you feel comfortable - try avoid using classes. (never use id)


Wait wut? Sounds intriguing but also terribly inefficient.


Css classes will complicate the css it can for example become hard to see what takes precedence when you mix classes and element. And it doesnt help that CSS is also has significant white space as in .foo.bar vs .foo .bar

So by practicing withot classes you will find that classes are rarely needed and in turn all your CSS get more simple - as long as you understand specifically. And you will also start to appreciate semantic HTML, and hopefully replace some of the divs with the appropriate semantic element!


I couldn’t agree more, and the hilarious thing is that I have spent much of the last few months doing exactly this. I’m writing yet another static site generator so by definition it must use classless HTML as the output. I am greatly enjoying the challenge of preserving semantic information while also making the output attractive. Thanks for the clarification!


Not just more specific rules, ones that just come later in source order too (with an identical specificity).

Oh, and more "important" rules too. "!important" overrides everything. Well, except more specific instances of !important, or instances of !important with the same specificity but later in source order.

Specificity is easy, the amount of specificity a selector has is measured using four different values represented by four single digits in four columns. (Of course, a single ID will override a thousand nested class selectors.)

And that's ignoring the origin of the rule (author, user, or user agent stylesheet).

And of course transitions override all of this.

Isn't CSS fun?




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: