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.

HTML Forum


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



Post a Project »

Find a Professional HTML Freelancer!

Find a Freelancer to help you with your HTML projects

FREE Outsourcing eBook!

Reply
Old 12-29-2006, 04:58 PM Class / ID
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
Can anyone explain the difference of these 2? I haven't a clue, when i'm coding I just pick one randomly, whichever works... I know this isn't good, as there must be a reason they are different.

Can anyone please explain?
feraira is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-29-2006, 05:43 PM Re: Class / ID
Matthew.'s Avatar
Experienced Talker

Posts: 37
Name: Matt or Matthew
Location: UK
Trades: 0
I don't know the exact differences myself. I am sure a quick google on the subject would find out for me but im now off so I'll be quick.

To me a class is like a category (i.e. we call some people chavs, emos etc lol) where as an ID is exactly that, a unique ID. (i.e. a social security number or fingerprint)
Matthew. is offline
Reply With Quote
View Public Profile Visit Matthew.'s homepage!
 
Old 12-29-2006, 09:03 PM Re: Class / ID
angele803's Avatar
Perfectly Imperfect

Posts: 1,772
Name: Stephanie
Location: Oklahoma
Trades: 2
You're headed in the right direction Matthew.
An ID MUST be UNIQUE. In other words, you can only use an ID one time. (Many browsers overlook that for now, but the correct way to use an ID is to only use it one time in your html)
A class can be applied to lots of different elements in your HTML.
You can remember the difference between the two by thinking that there are many people in a class, but each person in the class has a UNIQUE ID.
__________________

Please login or register to view this content. Registration is FREE
angele803 is offline
Reply With Quote
View Public Profile
 
Old 12-30-2006, 06:49 AM Re: Class / ID
Ultra Talker

Posts: 256
Location: Auckland, New Zealand
Trades: 0
Not the best definition for ID, CSS puts it as a unique identifier for an element, very vague, basically it doesn't mean one time only use, it means it can not be used on another element within the same document. You can use it more than once as long as it's a different document/page/markup whatever, just don't use it twice in the same document.

I usually use IDs to structure a page, since you usually only have 1 header in a page, 1 footer in a page, so an ID being used for these areas makes sense, because they only appear once on that page (well should only appear once)

Not only that, IDs can also be used as bookmarks within a page, meaning you can directly link to those certain areas, e.g. <a href="#footer">Check out my footer</a> will skip to my footer area, which is the location I gave the ID footer.

Classes can be used more than once, usually when you need multiple elements to take on the same styles. Though if you get comfortable with CSS Selector Specific, you can eliminate over using classes.

An example is using it to center text within block elements, you might have many elements that you want to center align the text, so you could have the style .center { text-align: center; } and can put that on multiple elements. When browsers get CSS 2.1 fully supported, you'll be able to add multiple classes to the one class attribute e.g. <div class="firstclass secondclass thirdclass"> and so on, just seperating them by a space.

Cheers,

MC
__________________
#------------------------------signature---------------------------------------------------------------------------------#
Quote:
I am well recognised for what I don't do than what I do. Chores are just one of those things.
mastercomputers is offline
Reply With Quote
View Public Profile Visit mastercomputers's homepage!
 
Reply     « Reply to Class / 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.13841 seconds with 12 queries