Click to See Complete Forum and Search --> : Class vs Id


Max^Power
12-06-2002, 05:05 AM
Can someone me tell me please what exactly is the difference between a class and an id and when i should use which.

Thanks

Rick Bull
12-06-2002, 05:38 AM
Use 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>

telconstar99
12-09-2002, 01:11 AM
IDs are useful if you wish to incorporate javascript as well. Check this explanation out:
http://www.htmlgoodies.com/beyond/classid.html

Robert Wellock
12-09-2002, 05:33 AM
The "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.