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
Old 08-15-2008, 06:28 AM Id Vs Class - Css
Average Talker

Posts: 21
Name: mahesh
Trades: 0
in css designing when we have to use ID and when class?
__________________
Learn Photoshop filters effects in easy steps visit
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
s_srimahesh is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-15-2008, 07:59 AM Re: Id Vs Class - Css
MatrixIT's Avatar
Skilled Talker

Posts: 85
Name: Dan
Trades: 0
This would be better off in the CSS Forum
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
MatrixIT is offline
Reply With Quote
View Public Profile
 
Old 08-15-2008, 10:12 AM Re: Id Vs Class - Css
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
It's a very simple distinction: class is meant to be used on multiple elements. Id is for unique elements, and should be used no more than once per page.

Also, you may have multiple classes on a single element, but you can have no more than one id per element.
__________________
Join me on
Please login or register to view this content. Registration is FREE

Last edited by wayfarer07; 08-15-2008 at 10:13 AM..
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 08-15-2008, 04:30 PM Re: Id Vs Class - Css
LadynRed's Avatar
Defies a Status

Posts: 10,016
Location: Tennessee
Trades: 0
You can also have an ID AND a class on an element.
__________________
Web Goddess & Web Standards Evangelist :) - Tables Be Gone !!

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

LadynRed is offline
Reply With Quote
View Public Profile
 
Old 08-15-2008, 05:16 PM Re: Id Vs Class - Css
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Or, if you're feeling frisky, an ID and multiple classes . To place multiple classes on an element, just put a space between them like this:
HTML Code:
<div class="funny news section" id="awesome">
Now, three sets of rules apply to one element. This brings up another interesting point, involving browser compatibility. Wouldn't you know it that all of the browsers see an element with multiple classes in the correct way, except for IE6 and below? IE6 is fine if you state all of the rules separately like this:
CSS
Code:
.funny {
/*rules*/
}
.news {
/*rules*/
}
.section {
/*rules*/
}
but not like this:
CSS
Code:
.funny.news.section {
/*rules*/
}
All of the browsers except for IE6 and below see the above rule as belonging to any element with all three of those classes on it. What IE6 sees, instead, is only the first class .funny. This means that now, instead of obeying the specific nature of the selector, all elements with only the single class, "funny" will have this rule. I almost pulled my hair out the first time this happened to me, I was so mad!
__________________
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 08-15-2008, 10:06 PM Re: Id Vs Class - Css
Skilled Talker

Posts: 77
Name: Bill Benson
Location: Florida
Trades: 0
I have trouble getting my hands around this one as well. Lets say you have a banner that appears twice on a page, identical both times. It appears twice. That means you should use class?

Header appears only once on every page. That means you should use id.

In the above example, what is the disadvantage to using class for all headers rather than id?

If you only intended to use the banner once per page but screwed up on a page and placed it twice using id I suspect it will work.

I understand when you are supposed to use each one more or less, I just don't understand why? Why not just always use class?
bill benson is offline
Reply With Quote
View Public Profile
 
Old 08-15-2008, 10:09 PM Re: Id Vs Class - Css
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
The distinction is more than just how many times you use the element, it also determines specificity.
__________________
Want new web resources every day? - Follow me on
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 08-15-2008, 11:54 PM Re: Id Vs Class - Css
Skilled Talker

Posts: 77
Name: Bill Benson
Location: Florida
Trades: 0
That helps and thanks!!!!

To clarify, an ID will have the highest specificity on the page?

It shouldn't appear more than once on a page but if it did, say in the case of the banner example, you had a banner using ID appear twice, is that proper coding or should you use class?
bill benson is offline
Reply With Quote
View Public Profile
 
Old 08-16-2008, 03:17 AM Re: Id Vs Class - Css
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
It will normally have the highest specificity, unless there is another combination with a higher point total, which would then take precedence. If you have more than one id of the same name on the same page, your code won't validate and it might not display properly in all browsers. If there is a change that it could repeat, that's the time to use a class.
__________________
Want new web resources every day? - Follow me on
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 08-16-2008, 08:26 PM Re: Id Vs Class - Css
Skilled Talker

Posts: 77
Name: Bill Benson
Location: Florida
Trades: 0
That clears it up a lot.

Thanks again.!!!!!
bill benson is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Id Vs Class - Css
 

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 1.06254 seconds with 12 queries