Class vs Id

Can someone me tell me please what exactly is the difference between a class and an id and when i should use which.

ThanksUse an ID when you want to apply style properties to one element only, use a class when you need it to be reusable, e.g.:


CSS:
#menu { /*MENU object only*/
position:absolute;
top:0px;
left:0px;
}
.center { /*For centering objects*/
text-align:center;
}

HTML:
<div id="menu">
<h2>Blah</h2>
<p class="center">Blah</p>
</div>
<p class="center">More blahs</p>IDs are useful if you wish to incorporate javascript as well. Check this explanation out:
<!-- m --><a class="postlink" href="http://www.htmlgoodies.com/beyond/classid.htmlThe">http://www.htmlgoodies.com/beyond/classid.htmlThe</a><!-- m --> "id" is a unique identifier and can only appear once within an XHTML document, the thing which makes attributes of type "id" special is that no two such attributes can have the same value; whatever the document language.

Joe obviously doesn't completely understand the full functionally of the "id" he seems to think it doesn't do anything different than class within HTML which is wrong, you'd probably notice that it you tried a completely table-less design using CSS-P :p.
 
Back
Top