Reply
The difference between classes and ids
Old 08-27-2007, 03:22 AM The difference between classes and ids
Experienced Talker

Posts: 40
Name: james
I am having trouble understanding the difference between using classes and ids. Could anyone help me out.
jamest is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 08-27-2007, 10:19 AM Re: The difference between classes and ids
mackaltman's Avatar
Super Talker

Posts: 135
Name: Mack Altman III
Location: Goose Creek, SC, USA
Although most of those who practice CSS don't pay attention to it, the difference between the ID and CLASS selectors is very simple.

CLASS selectors may be used as many times as possible on a page; however, ID is a unique tag that may only be used once per page. Although, you will find others who use them both the same way, that isn't the correct practice of HTML/XHTML.

Also with classes, you can do things like p.classname, which would identify all P tags that had "classname" as their CLASS.

I hope this helps you out.
__________________
Mack Altman III
TheGView Owner
My Biggest Pet Peeve: "Web Designers" who have no artistic skill.


Last edited by mackaltman : 08-27-2007 at 10:27 AM.
mackaltman is offline
Reply With Quote
View Public Profile Visit mackaltman's homepage!
 
Old 08-27-2007, 11:23 AM Re: The difference between classes and ids
Experienced Talker

Posts: 40
Name: james
thanks that helped me alot.
jamest is offline
Reply With Quote
View Public Profile
 
Old 08-29-2007, 10:17 AM Re: The difference between classes and ids
Super Talker

Posts: 127
Name: Jess Weiss
Location: Massachusetts
Wow. I had no idea. So, in my pages, would everything still render correctly if I changed all of my <div id=> tages to <div class=> tags when they are used more than once?
__________________
"If you worried about falling off the bike, you'd never get on it" - Lance Armstrong

"The problem with people who have no vices is that generally you can be pretty sure they're going to have some pretty annoying virtues." - Elizabeth Taylor
lynnema is offline
Reply With Quote
View Public Profile Visit lynnema's homepage!
 
Old 08-29-2007, 01:45 PM Re: The difference between classes and ids
angele803's Avatar
Perfectly Imperfect

Posts: 1,609
Name: Stephanie
Location: Oklahoma
Quote:
Originally Posted by lynnema View Post
Wow. I had no idea. So, in my pages, would everything still render correctly if I changed all of my <div id=> tages to <div class=> tags when they are used more than once?
Yes, everything should look the same if you change your IDs to classes. It is really best to just use an ID once (per document) and use classes for things that appear more than once.
angele803 is offline
Reply With Quote
View Public Profile
 
Old 08-29-2007, 04:00 PM Re: The difference between classes and ids
tripy's Avatar
Fetchez la vache!

Posts: 2,162
Name: Thierry
Location: In the void
An id is primarily targeted for javascript, in my mind.
It allows you to put a tag on a particular element of the page, to access it later and alter it state dynamically.

Not too, although I don't think many people knows that, that you can put multiples classes on an element:
HTML Code:
<div class="bold noPadding red">
sgdgf
</div>
will apply all the 3 classes, in the order they are specified, on the content of the div.

On contrario, an element cannot have multiples Id.
__________________
Listen to the ducky: "This is awesome!!!"

tripy is online now
Reply With Quote
View Public Profile
 
Old 08-29-2007, 09:48 PM Re: The difference between classes and ids
Experienced Talker

Posts: 40
Name: james
Thank You for the help i now understand the difference between the two
jamest is offline
Reply With Quote
View Public Profile
 
Old 08-31-2007, 05:47 AM Re: The difference between classes and ids
mackaltman's Avatar
Super Talker

Posts: 135
Name: Mack Altman III
Location: Goose Creek, SC, USA
I'm glad that you found that of use.
__________________
Mack Altman III
TheGView Owner
My Biggest Pet Peeve: "Web Designers" who have no artistic skill.

mackaltman is offline
Reply With Quote
View Public Profile Visit mackaltman's homepage!
 
Reply     « Reply to The difference between classes and ids
 

Thread Tools

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Webmaster Resources Marketplace:
Software Development Company | Webhosting.UK.com | Text Link Brokers 


   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.14110 seconds with 12 queries