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.
Yes, you can. But note that Id's must be unique within your html file, while classes can be used in multiples elements.
In Html for an element ID name starts with the “#” symbol followed by a unique name assigned to it. On the other hand class assigned to an element has its name starts with “.” followed by class name. Only one ID selector can be attached to an element. Multiple class selectors can be attached to an element.
Remember the difference between Class and ID: A Class name can be used by multiple HTML elements, while an ID name must only be used by one HTML element within the page.
The difference between an ID and a class is that the first one is unique, and the second one is not. This means that each element can have only one ID, and each page can have only one element with that ID. When using the same ID on multiple elements, the code won't pass validation.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With