Another "morality" question: ID or class?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I know the technical differences between ID and class, but when (in a
zen/standards/schematic/just-to-be-good sense) is it appropriate to use ID
or class?

I'm assuming class should be used almost all the time, especially when
working with style sheets, and that ID should only be used to reference
particular sections of a document from other documents?

Re: Another "morality" question: ID or class?

Quoted text here. Click to load it

<div id="header">
<ul><li>menu item 1</li></ul>
<div id="content">
<h1 class="titles" id="header1">Title</h1>
<div id="footer">
Copywrite ...<a href="#header1">Head</a>

Very nice for making templates, especially templates using include files.
Adrienne Boswell
Please respond to the group so others can share

Re: Another "morality" question: ID or class?

spaghetti wrote:
Quoted text here. Click to load it

id is for unique items - ie: there should only be one specific id per page
class is for common items - ie: items which share common features could
be of the same class

for example, I have the id "Kae Verens", and am of the class "web
developer" - the id is unique, but the class is common.


Re: Another "morality" question: ID or class?

Quoted text here. Click to load it

You use ID when there's just one instance of an element you want styling.
You use class when there are multiple elements you want to style with one

Classes should actually be used rarely, because you should be able to use
nested selectors in CSS in most cases (such as '#content p strong {
stuff }')

ID attributes are a good thing to use in HTML because they identify an
element and can also be used for page anchors.

Site Timeline