Another "morality" question: ID or class?

S

spaghetti

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?
 
A

Adrienne

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?

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


Very nice for making templates, especially templates using include files.
 
K

Kae Verens

spaghetti said:
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?

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.

Kae
 
P

PTG

spaghetti said:
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?

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
selector.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top