Is there anything wrong with having a css class and id with the same name? Like .footer for the article/post's footer and #footer for the page footer.
+6
A:
Nope, perfectly acceptable.
A class is defined using a .
and an ID is defined using a #
. So as far as the browser is concerned, they're two totally separate items.
The only thing to be careful of is generating any confusion for yourself. It's probably best practise to keep the names different purely for code readability, but there's no harm in them being the same.
GenericTypeTea
2010-07-15 08:31:47
Ditto. And with HTML5 some elements will have the same name like footer. `footer.footer#footer` may be confusing :)
Felipe Alsacreations
2010-07-15 08:41:10
@Felipe - that'll get confusing quickly!
What
2010-07-15 09:50:51
From the example of OP with footer and your concise explanation, my first thought was for these new elements but in fact, it should be the contrary: no more div.footer and div#footer! They'll be replaced by `footer` (targeted by, say, `body>footer` and `section footer`) and no need for class and id anymore in many cases. My bad.
Felipe Alsacreations
2010-07-15 13:16:44
+1
A:
No, there is nothing wrong, but it might be better to use different names to not confuse other developers. It is more (human) error prone to use different names.
Thariama
2010-07-15 08:34:49
A:
HI All
This is Absolutely right use same name class and ID but dose not use same name id and same name class..
Prashant
2010-07-15 11:57:31