The key thing is that an ID identifies a specific element within a page and
therefore must be unique.
Classes mark elements as members of a group and can be used multiple times.
So why not always using Class over ID ? One of the main
reason may be related to javascript that intensively uses ID such as in the
function getElementById().
Another reason is that an element may have both a class and an ID
<div class="tab" id="tab1"> Tab 1 </div> <div class="tab" id="tab2"> Tab 2 </div>; |
Then in your CSS you can do::
div.tab { background-color: #F00; } div#tab1 { text-decoration: none; } |
Please follow and like us: