3 ms·
Sure, the author is describing good practice, not best practice. If you have a choice, use class, then if you need to modify a specific use of the class, use i
by bluetwo 9y ago
Sure, the author is describing good practice, not best practice.
If you have a choice, use class, then if you need to modify a specific use of the class, use id.
I would still use .footer instead of #footer. Of course you should consider <footer> as well.
- ars 9y ago> I would still use .footer instead of #footer Why?
- morley 9y agoI think the preference against ids is covered over point #2 about specificity. id styles will always override class styles, so when you're trying to apply a class-based style guide to an element that's already been styled with an id, you end up having to use !important which just creates a similar specificity problem for someone else down the line. Of course, you can still do this if you want to. To quote Chris Rock, "you can drive a car with your feet if you want to." But if you work on a large code base that lots of developers have touched, and lots of future developers will touch, you run into these issues all the time. And the bugs that come about can be tough to spot and to fix.
- ars 9y agoIf it's been styled with an id then it's already specially called out in the CSS. Either remove that, or add the id to the selector with the style.
- deleted 9y ago[deleted]
- bluetwo 9y agoI agree with other poster. For me it's a matter of doing things the same way so when I need to make an update to the code in a year it's intuitive. "Be kind to your future self" is my motto.
- sametmax 9y agoI would use ".xed-footer" for reusable footer bearing the x caracteristic. And #main-footer for the stuff that stick at the bottom of most of my pages with unique caracteristics. Way more self describing. No team member will ask which one is reusable and which one is not.
- z3t4 9y agoYou can have many classes!! <div class="footer special enterprise"> .footer.special.enterprise { background-color: blue; }
- bluetwo 9y agoThat, too, yes.