SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Class Vs id

  1. #1
    SitePoint Member
    Join Date
    Jan 2004
    Location
    Michigan USA
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Class Vs id

    I've been using css for some time. I like the way I can stack classes
    <p class="si sw de">

    I do not understand the difference between classes and id's. W3C was no help nor was the core css manuals.
    Please explain in wordsa of few syables.

    Thanks
    dwright118194mi@comcast.net

  2. #2
    I am obstructing justice. bronze trophy fatnewt's Avatar
    Join Date
    Jul 2002
    Location
    Ottawa, Canada
    Posts
    1,766
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ID refers to a unique element, to which styles can be applied directly.

    Class refers to a particular TYPE of element - such as a particular class of link which is styled differently than others.

    Classes can apply to several elements, but id is unique.

    If you had an absolutely positioned div, for example, you could only really apply the style to one item individually (unless you were looking for that demented overlapping look.)
    Colin Temple [twitter: @cailean]
    Web Analyst at Napkyn


  3. #3
    SitePoint Wizard rbutler's Avatar
    Join Date
    Jul 2003
    Location
    Springfield, MO
    Posts
    1,867
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    CSS class: Can use and reuse anywhere on your page(s)

    IDs: Use only once on a page, for a navigational purpose or something unique.
    Ryan Butler

    Midwest Web Design

  4. #4
    SitePoint Wizard megamanXplosion's Avatar
    Join Date
    Jan 2004
    Location
    Kentucky, USA
    Posts
    1,099
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ID should only be used by one element (like a person who carries their ID in their wallet), classes can be re-used as much as needed.

    EDIT: woah, two people posted before me while I was writing my message lol

  5. #5
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i come across this question so often...i wish we could have a sticky thread on it (then again, people will still ignore it and start a new one...)
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  6. #6
    Phil fillup07's Avatar
    Join Date
    May 2002
    Location
    Jacksonville, FL
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I definately agree...
    Sticky a FAQ, and if someone else posts it give them a link to the FAQ sticky and close the thread.

  7. #7
    SitePoint Addict
    Join Date
    Dec 2002
    Posts
    386
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    IDs also help for forms and js
    and you can also link to them in modern browsers the way you do to an anchor


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •