tags:

views:

71

answers:

1

Perhaps this question has been asked elsewhere, but I'm unable to find it. With HTML5 and CSS3 modules inching closer, I'm getting interested in a discussion about the way we write CSS.

Something like this where selection is done via element order and pseudo-classes is particularly fascinating. The big advantage to this method seems to be complete modularization of HTML and CSS to make tweaks and redesigns simpler.

At the same time, semantic IDs and classes seem advantageous for sundry reasons. Particularly, direct linking, JS targeting, and shorter CSS selectors. Also, it seems selector length might be an issue. For instance, I just wrote the following, which would be admittedly easier using some semantic HTML5 elements:

body>div:nth-child(2)>div:nth-child(2)>ul:nth-child(2)>li:last-child

So what say you, Stack Overflow? Is the future of CSS writing focused on element order and pseudo-classes? Or are IDs and classes and the current ways here to stay?

(I'm well aware the IDs and classes have their place, although I am interested to hear more ways you think they'll continue to be necessary. I don't want to misrepresent this or frame it as "Are pseudo-classes ID killers?" The discussion I'm interested in is bigger-picture and the ways writing CSS is changing.)

+2  A: 

I think that's an unreadable abomination which will mysteriously stop working when the HTML changes.

Order-based selectors are completely non-self-documenting.
If someone else takes over the project, and the HTML changes, he will have no idea what the selector is supposed to select, and will be hard-pressed to fix it correctly.

This is especially important if any part of the HTML is automatically generated.

SLaks
Great point, and my example was certainly more a model of how **not** to do things. nth-child seems particularly problematic, especially as you are looking to target elements by specific location rather than a formula or "odd" and "even." That example aside, would you hold the same position regarding someone writing much more deftly than myself? Particularly the linked example? http://camendesign.com/design/
Joshua Cody
I'll go ahead and mark this as answered because you provided a great counterpoint to my suggestion. My hope was for more discussion from others, but thanks so much for your input!
Joshua Cody