| 7:39 pm on Mar 25, 2003 (gmt 0)|
Welcome to Webmaster World!
An id can only be used once per page. So, use id for main layout elements that you only use once per page and class for elements that will use the class more than once.
| 7:43 pm on Mar 25, 2003 (gmt 0)|
Check out Nicks CSS Crash Course [webmasterworld.com] for some good reading.
| 7:53 pm on Mar 25, 2003 (gmt 0)|
that's great! thank you.
| 5:58 am on Mar 27, 2003 (gmt 0)|
Best way to think about it: id can be the target for a hyperlink. So you can do
and link to it with an
Not only is the former sematically cleaner, it is required in xhtml 1.1, where the name attribute has been dropped.
So an id must be unique on a page, and should carry some semantic meaning (ie, as something you might conceivably link to). A class is more generic, denoting a set of element of the "same" sort.
| 7:28 am on Mar 27, 2003 (gmt 0)|
Welcome [webmasterworld.com] to Webmaster World, professor! ;)
To further clearify your excellent explanation: just think about the names...
ID = identifier... class = group...
Every person has some form of unique ID, a drivers licence or passport or whatever, and it works the same way on Web pages.
ID = unique
class = group, no matter if there's one or a few thousand elements in the group
| 7:59 pm on Mar 27, 2003 (gmt 0)|
in that case, what would be the point of ever assigning styles to elements via the ID attribute? wouldn't it make more sense to always set styles with a class declaration and just to use ID for identifying?
| 8:06 pm on Mar 27, 2003 (gmt 0)|
You also may apply a class to a bunch of items, but need to slightly modify a few of them based on their id, in those cases you use both referencing techniques.
border:thin black groove;