Mike3456 Posted July 20, 2016 Share Posted July 20, 2016 (edited) The value of id attribute is supposed to be unique. It doesn't make any sense to use a CSS selector with an element name in front of #id_name, in the sense that no two elements can have the same id value. W3C website implies that two different elements can have the same id. Theoretically, there is a special case for h1#chapter1 where there is a different element with id=chapter1 but in such case there could not be h1 with id=chapter1 in the same document anyway. Such special cases have to be described in any spec and not left out to speculations This excerpt is from --------------------------------------------- https://www.w3.org/TR/css3-selectors/#id-selectors: The following ID selector represents an h1 element whose ID-typed attribute has the value "chapter1": h1#chapter1 The following ID selector represents any element whose ID-typed attribute has the value "chapter1": #chapter1 The following selector represents any element whose ID-typed attribute has the value "z98y". *#z98y ---------------------------------------------- Edited July 20, 2016 by Mike3456 Link to comment Share on other sites More sharing options...
dsonesuk Posted July 20, 2016 Share Posted July 20, 2016 It easily gives you the element type the id is applied to, so you can group these element type making easier to maintain maybe? Link to comment Share on other sites More sharing options...
Ingolme Posted July 21, 2016 Share Posted July 21, 2016 The ID is unique within the page. If, for any reason, you don't want to select an element that's not an <ht> you can use h1#chapter1. Usually you won't need to, but the example is there to show it's allowed. IDs may be unique within a page, but one same stylesheet can apply to many different pages. Perhaps on some of the pages #chapter1 is not an <h1> element. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now