Class and ID Selectors (CSS question)

M

Matt Beckwith

Is there any good reason to use ID selectors? It seems to me they're
effectively the same as class selectors, but limited by only being able to
be used once.
 
A

Anders Thorsen Holm

Matt said:
Is there any good reason to use ID selectors? It seems to me
they're effectively the same as class selectors, but limited by
only being able to be used once.

As far as I know, they can also be used as targets for internal links.
Example:

<div id="menu">
<ul>
<li><a href="#chp1">Chapter 1</a></li>
<li><a href="#chp2">Chapter 2</a></li>
</ul>
</div>

<div id="chp1">
<h1>Chapter 1: How it all began</h1>
<p>yadda-yadda-yadda</p>
</div>

<div id="chp2">
<h1>Chapter 2: And what happened next</h1>
<p>hummena-hummena-hummena</p>
</div>



Although it - suprise - doesn't seem to work in Netscape 4, but hey, no
loss here.
 
D

David Dorward

Matt said:
Is there any good reason to use ID selectors? It seems to me they're
effectively the same as class selectors, but limited by only being able to
be used once.

If purely CSS terms, they have a higher specificity, but they are useful for
things beyond CSS.
 
D

David Dorward

Daniel said:
I guess you could use them as targets in a DIV statement as you suggest.
But isn't that what anchor tags are for?

What are you taking about? Please quote properly.

After digging around in the archives it appears to be a query are id
attributes to define document fragments for link targetting.

The answer is "no", anchors for fragment identifiers have been superseded by
the id attribute on just about any element.

It makes more sense semantically (IMO) and makes it a lot easier to pull of
tricks such as http://stone.thecoreworlds.net/software/frag/
 

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

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top