Class and ID Selectors (CSS question)

Discussion in 'HTML' started by Matt Beckwith, Jul 12, 2003.

  1. 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.
    Matt Beckwith, Jul 12, 2003
    #1
    1. Advertising

  2. Matt Beckwith wrote:

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



    --
    Anders Thorsen Holm | http://www.daimi.au.dk/~zoolook/
    "It's hard to be religious when certain people are never incinerated by
    bolts of lightning."
    - Calvin, Attack of the Deranged Mutant Killer Monster Snow Goons
    Anders Thorsen Holm, Jul 12, 2003
    #2
    1. Advertising

  3. David Dorward, Jul 12, 2003
    #3
  4. Daniel Doman wrote:

    > 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/

    --
    David Dorward http://david.us-lot.org/
    Redesign in progress: http://stone.thecoreworlds.net/
    Microsoft announces IE is dead (so upgrade):
    http://minutillo.com/steve/weblog/2003/5/30/microsoft-announces-ie-is-dead
    David Dorward, Jul 13, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Derek Clarkson
    Replies:
    3
    Views:
    379
    Derek Clarkson
    Nov 7, 2003
  2. Nik Coughin

    css - descendant selectors

    Nik Coughin, Jan 28, 2004, in forum: HTML
    Replies:
    2
    Views:
    387
    Alliss
    Jan 29, 2004
  3. Jeanne D

    Question about CSS selectors

    Jeanne D, Oct 15, 2005, in forum: HTML
    Replies:
    8
    Views:
    379
    Jeanne D
    Oct 16, 2005
  4. Jon Slaughter

    css selectors

    Jon Slaughter, Apr 17, 2007, in forum: HTML
    Replies:
    13
    Views:
    944
    Ben C
    Apr 21, 2007
  5. Nathan Sokalski

    Help With CSS Selectors

    Nathan Sokalski, Mar 24, 2008, in forum: ASP .Net
    Replies:
    5
    Views:
    342
    Just Me
    Mar 24, 2008
Loading...

Share This Page