CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignCSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 19th, 2004, 10:13 AM
Rex Riley's Avatar
Rex Riley Rex Riley is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Westminster, MD
Posts: 17 Rex Riley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Newbie: class vs id selector?

I'm a CSS newbie and have a basic question.

It seems that the selectors class and id do ecaxtly the same thing. So this begs the question: Which one should I use and why is it better then the other selector?

I see that both should not begin with a number (css1) and I am unclear about the requirement for the selector to be unique.

Thanks Folks!

Reply With Quote
  #2  
Old June 19th, 2004, 10:17 AM
jamieB jamieB is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2002
Posts: 596 jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 3 h 19 m 33 sec
Reputation Power: 18
you can use either in most situations but you should really use id for unique elements otherwise any js or other code using DOM to access and manipulate the elements will screw up. use class for something of which there may be many.

Reply With Quote
  #3  
Old June 19th, 2004, 10:34 AM
Akh's Avatar
Akh Akh is offline
|<.+#f@#+.&.|
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2002
Location: norway
Posts: 2,715 Akh User rank is Brigadier General (60000 - 70000 Reputation Level)Akh User rank is Brigadier General (60000 - 70000 Reputation Level)Akh User rank is Brigadier General (60000 - 70000 Reputation Level)Akh User rank is Brigadier General (60000 - 70000 Reputation Level)Akh User rank is Brigadier General (60000 - 70000 Reputation Level)Akh User rank is Brigadier General (60000 - 70000 Reputation Level)Akh User rank is Brigadier General (60000 - 70000 Reputation Level)Akh User rank is Brigadier General (60000 - 70000 Reputation Level)Akh User rank is Brigadier General (60000 - 70000 Reputation Level)Akh User rank is Brigadier General (60000 - 70000 Reputation Level)Akh User rank is Brigadier General (60000 - 70000 Reputation Level)Akh User rank is Brigadier General (60000 - 70000 Reputation Level)Akh User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 4 Weeks 17 h 42 m 44 sec
Reputation Power: 642
the html4.01 specs explains the difference between id and class,
and the uses of these attributes, and why id have to be unique.

http://www.w3.org/TR/html401/struct/global.html#h-7.5.2
http://www.w3.org/TR/html401/struct...anchors-with-id

Reply With Quote
  #4  
Old June 19th, 2004, 01:11 PM
kk5st's Avatar
kk5st kk5st is offline
Thanks Johnny Hart (BC) R.I.P.
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: May 2003
Location: Dallas
Posts: 4,674 kk5st User rank is Brigadier General (60000 - 70000 Reputation Level)kk5st User rank is Brigadier General (60000 - 70000 Reputation Level)kk5st User rank is Brigadier General (60000 - 70000 Reputation Level)kk5st User rank is Brigadier General (60000 - 70000 Reputation Level)kk5st User rank is Brigadier General (60000 - 70000 Reputation Level)kk5st User rank is Brigadier General (60000 - 70000 Reputation Level)kk5st User rank is Brigadier General (60000 - 70000 Reputation Level)kk5st User rank is Brigadier General (60000 - 70000 Reputation Level)kk5st User rank is Brigadier General (60000 - 70000 Reputation Level)kk5st User rank is Brigadier General (60000 - 70000 Reputation Level)kk5st User rank is Brigadier General (60000 - 70000 Reputation Level)kk5st User rank is Brigadier General (60000 - 70000 Reputation Level)kk5st User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 3 Days 15 h 15 m 50 sec
Reputation Power: 687
Think of it this way;

A class refers to anything having the characteristic class_name, such as boy, girl, redhead, blond, bald, righthanded or lefthanded. As you can see, a class may have a variety of individuals and an individual may belong to a variety of classes.

An id, on the other hand, refers to only one individual and must be unique within the scope (page). Thus there is only one individual named Mary_Jones, and Mary_Jones refers only to that one individual.

cheers,

gary
__________________
There are those who manage to build a web site without knowing what they're doing; thereby proving to themselves they do, indeed, know what they're doing.

My html and css workshop, demos and tutorials.
Ask a better question, get a better answer.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignCSS Help > Newbie: class vs id selector?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT