Reputation: 27852
Why would you want to do:
h1#chapter1 { text-align: center }
Instead of
#chapter1 { text-align: center }
If an id is supposed to be unique in a document tree?
Upvotes: 0
Views: 51
Reputation: 6285
Usually it is done to make it easy to tell exactly what sort of element has the ID without having to leave the stylesheet. I think would also have a higher specificity than just #element, so you could override a standard #element selector with div#element.
Upvotes: 1
Reputation: 24334
Strange question, perhaps you have the same id on different elements across different pages that share the same stylesheet?
E.g. on home.html you have <h1 id="title">
on about.html you have <h2 id="title">
But they both use same stylesheet and you want to apply a style for the homepage title only..
Also it wouldnt make sense to make the CSS syntax inconsistent across different kind of selectors. Would cause more confusion then it was worth.
Upvotes: 0
Reputation: 10736
I do that to let the next developer know what element the ID is on.
I do not do that on divs, sections, or any "containers".
Upvotes: 0