difference in class and id css
can anyone give a good explanation in the difference between an id and a class in CSS I've found that I can really use them interchangeably.. so is there a right time to use one or the other?
A patch is a piece of software which replaces old bugs with new bugs.
West Chatham Homes | Custom American made Caps | Custom Handmade Knives
andy206uk posted this at 00:26 — 26th November 2006.
He has: 1,758 posts
Joined: Jul 2002
Hi,
An ID should always be unique, therefore you should only use them to identify unique parts of the page for instance your header. Each ID should only appear on a page ONCE.
Classes can be used as many times as you like.
At least... that's how I understand it...
Andy
Roo posted this at 19:26 — 26th November 2006.
She has: 840 posts
Joined: Apr 1999
Yes, that about sums it up . I've never tried it, but if you were to try to use an ID more than once I don't think it would even display more than once. Am I right or wrong about that?
Roo
andy206uk posted this at 19:53 — 26th November 2006.
He has: 1,758 posts
Joined: Jul 2002
That's how it should work, but in my experience most browsers just treat it like a class and repeat the styling. The HTML validator growls at you if you do use them more than once though...
Andy
Megan posted this at 14:09 — 27th November 2006.
She has: 11,421 posts
Joined: Jun 1999
The browsers have no problem with duplicate ID's. The validator does.
Think of Classes and ID's this way: a class is a group. Anyone can belong. An ID is an identification number - it has to be unique to one individual.
Megan
Connect with us on Facebook!
blackhawkpowers posted this at 23:32 — 27th November 2006.
They have: 38 posts
Joined: Nov 2006
alright thanks for the help guys
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.