- In a Q&A article on Smashing Magazine I answered a question about how to look at CSS and determine if it's good or bad.
-
Harry Roberts expounded upon my answer with lots more specific examples about bad things you can find in CSS (e.g. magic numbers, qualified classes, too vague of selectors). Harry says in this article:
Use IDs in HTML for fragment identifiers and JS hooks, but never in CSS.
- Jeffrey Zeldman reacts to this and defends using IDs. Jeffrey compares abandoning ID's to OOCSS and avoiding descendant selectors.
- We have Jeffrey on ShopTalk to discuss. We don't spend too much time disagreeing - but instead focus on a much bigger agreement: being too dogmatic about these things is the worst possible stance.
- Totally coincidentally, we have Harry Roberts on ShopTalk next week.
Now my turn again. I love blogging.
I feel like if anyone gets off-put by Harry's writing, this article or any others, is that he sometimes comes off as being dogmatic. If that term doesn't mean anything to you, just think of it as inflexible thinking. This is the way things are dammit and that's that. Having strong opinions is awesome, having inflexible ones is not. Writing about what works for you is awesome, writing iron-clad manifesto's is not.
I've met Harry. He's a nice guy. I'm not sure how dogmatic he is in his thinking (I doubt much). We'll talk about that on ShopTalk.
Jeffrey called "bunk" on the decree that ID's should never be used:
Say it with me: There is nothing wrong with id when it is used appropriately (semantically, structurally, sparingly). There is plenty wrong with the notion that class is always preferable to descendant selectors and semantic, structural ids.
To me that edges just as close to dogmatism as Harry did. And I'm guilty of this as well. I wrote about this in my article "A Line In The Sand, A Story About Meaty Chili and Using Classes":
I'm not going to use ID's to style things. No compromise. Even if an ID might seem like it could save me in a short term way, the long term benefits of never using them are greater.
Avoiding ID's altogether has lead to a better CSS authoring experience for me. I probably should have framed it more like that, but hey.
I feel like Jeffrey thinks that avoiding ID's means over-classing everything else, giving up on the cascade, and not using intelligent selectors that encourage clean markup. I don't think ID's have anything to do with those things. Over-classing is dumb, don't do that, and don't think that that's what OOCSS means (I think of it like: find a pattern, give that pattern a class). The cascade is still useful, but in limited ways. You could argue it hurts as much as it helps. And finally, I'm all about descendant selectors. They work equally well with classes as with ID's. Better, I'd argue, since the class is re-usuable.
I also feel Jeffrey has a deeper perspective on this as Harry or I might. As we talked about on ShopTalk show, Jeffrey worked through some eras where markup was extremely nasty and helped usher in an age of clean markup that we're used to seeing today. I can understand being nervous if he feels things move back the other direction.
“Bad Code”, Dogmatism, etc. is a post from CSS-Tricks
Source : internetwebsitedesign[dot]biz
0 comments:
Post a Comment