PDA

View Full Version : CSS difference between CLASS and ID attributes


vindaloo
04-04-2003, 02:59 AM
Hi,

I am just starting to learn HTML using 1st Page, and have decided that the best thing to do is go straight into using CSS. One thing I can't see at the moment is the difference between the CLASS attribute and the ID attribute, as in
.green { color: green }
<P CLASS=green>Hello!</P> and
#green { color: green }
<P ID=green>Hello!</p>

I've gone though a couple of tutorials, but they didn't explain the practical differences. My problem is that I can't see when you would use ID instead of CLASS.

Apologies if this has been asked before, but I didn't have any luck with searching the forums.

Thanks in advance.

Joe the Large
04-04-2003, 08:11 AM
This is an excellent resource. Web Design Group CSS Guide (http://www.htmlhelp.com/reference/css/structure.html)

HTH

Joe

DCElliott
04-05-2003, 02:56 PM
Briefly

ids are unique

classes are reusable

An id is used to apply CSS, but can do more than that, since it becomes a document object that can be dynamically manipulated. But that goes beyond the scope of your question. In practical terms, ids are often used for structural components of your page (id="menu" id="maincontent" id="footer") while classes are used for general presentation (class="hilighted" class="announcement")

DE

vindaloo
04-08-2003, 06:55 AM
Thanks Joe & DE, that answers my question perfectly.

DCElliott
04-08-2003, 10:40 AM
Vindaloo

You should try this reference, it suits your name: http://freespace.virgin.net/sizzling.jalfrezi/frames/fstyles.htm

Make sure you have some raita on hand. :p

DE

vindaloo
04-09-2003, 01:37 AM
Thanks, another good reference to add to my collection! I've posted my progress so far just to check I'm not heading off in the wrong direction!

http://developers.evrsoft.com/forum/showthread.php?s=&threadid=1368