August 28, 201115 yr When creating a Navigation Menu which ID selector should one, ID's or Class? I am asking because I notice some use ' Class ' and others ' ID's ' . Thank you Edited August 28, 201115 yr by MartyBoi
August 28, 201115 yr When creating a Navigation Menu which ID selector should one, ID OR Class? I am asking because I notice some use ' Class ' and others ' ID's ' . Thank you Well, for validation purposes, ID's can only be used once per page, where as classes can be used multiple times. So, one may code a Menu in list form like this; <ul id="main-nav"> <li class="main-nav-button">menu item 1</li> <li class="main-nav-button">menu item 2</li> <li class="main-nav-button">menu item 3</li> <li class="main-nav-button">menu item 4</li> </ul>
August 28, 201115 yr It's completely personal. Some people advocate only using ID's. Other's think they are useless. Some use ID's for certain things only and others will chop and change on a whim. As pointed out above the only difference between them is ID's have to be unique. Use them or don't use them. Doesn't make any difference.
August 28, 201115 yr Aim for classes wherever you can. It's a good idea to write your CSS aiming to get the result you want while using as little specificity as possible, to allow for future maintenance and more specific requirements to override it. That doesn't mean yu shouldn't include IDs in your markup, they're absolutely vital as fragment identifiers (to link to a specific section of a page, for example).
Create an account or sign in to comment