Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

CSS Forum


You are currently viewing our CSS Forum as a guest. Please register to participate.
Login



Reply
Difference between Class and ID?
Old 03-13-2009, 01:48 PM Difference between Class and ID?
Ultra Talker

Posts: 316
Trades: 0
I've never really understood the difference between class and ID (. & #).

From what I've read you should use ID when you only use that style once and class if you use it multiple times but that doesn't seem right to me.

Can anyone clear this up for me?

Thanks.
Joe3000 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-13-2009, 03:01 PM Re: Difference between Class and ID?
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
An ID may only appear once on the page. Only one ID may be used per element. A selector with an ID is higher in the Cascade than a Class in a CSS document, in other words, it has greater specificity by default than a class.

A class, on the other hand, may be used multiple times on a single element, and may appear multiple times throughout the page.

An ID is for unique elements. A class is for generic, reusable elements.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 03-13-2009, 08:12 PM Re: Difference between Class and ID?
vangogh's Avatar
Post Impressionist

Posts: 10,688
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
Just what Abel said. An id should be used once and only once per page and a class can be used as many times as you want. You can use the same id on different pages though. Each page can have <div id="header"> since each page will likely have a header. However no single page would have more than one header.

Sometimes your choice can seem a bit arbitrary. For example you could make your header a class <div class="header"> and then use it only once on the page, but technically you should use an id when something is only meant to be used once per page and use classes for things that can be used more than once, even if you only end up using them once per page.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Reply     « Reply to Difference between Class and ID?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





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



Page generated in 0.13422 seconds with 12 queries