SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Guru coiL's Avatar
    Join Date
    Sep 2001
    Location
    QLD, Australia
    Posts
    666
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question .name or #name ?

    Hi,

    I've never really used CSS for anything but font styles, but today I was doing some reading and playing with other CSS elements. I have always written my stylesheets using .classname I've noticed that some people use #classname

    which should I be using?

    Thanks.
    coiL
    "cradled in the learning curve"

  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)
    #something is not the name of a class.

    .something is used for objects that appear multiple times. For example, I could have many paragraph elements set up as:

    <p class="something">


    However, #something is used to define formatting for a specific element. (I most commonly use this for div elements in layout).

    <div id="something"> would refer to the #something definition in the stylesheet. Only one element on the page can have that id.

    # = unique.
    . = repeated class.


    Edit:

    by the way, if you're just using CSS for font styles, then you'll probably only use classes so you can repeatedly use certain styles.
    Colin Temple [twitter: @cailean]
    Web Analyst at Napkyn


  3. #3
    SitePoint Wizard
    Join Date
    Nov 2000
    Location
    Chico, Ca
    Posts
    1,125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I never really figured out why one should use one over the other, I use classes myself.
    "Happiness doesn't find you, you find happiness" -- Unknown
    www.chuckknows.com

  4. #4
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ID's are for specific elements, it allows you to have generic classes, but apply styles directly to a specific element, keeping all of the style information out of the HTML markup, as well as making your CSS file smaller, by generalizing more.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  5. #5
    SitePoint Wizard Bill Posters's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ... + ids allow you to address specific elements via the DOM (javascript/dhtml).
    New Plastic Arts: Visual Communication | DesignateOnline

    Mate went to NY and all he got me was this lousy signature

  6. #6
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That doesn't specifically relate to CSS definitions, but yes, they do that too
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  7. #7
    SitePoint Wizard Bill Posters's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    (appropriate) use of css definitions is critical to dhtml and anyone wanting to set or alter an element's css attributes on the fly.

    I'd say that's pretty relevent.
    New Plastic Arts: Visual Communication | DesignateOnline

    Mate went to NY and all he got me was this lousy signature

  8. #8
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, i'll give you that one, .

    (I think this thread was more on what #blah did in stylesheets, but I'm not the topic nazi, lol, so whatever.)
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  9. #9
    SitePoint Guru coiL's Avatar
    Join Date
    Sep 2001
    Location
    QLD, Australia
    Posts
    666
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I knew I had posted somewhere.
    Thanks for the replies
    coiL
    "cradled in the learning curve"


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
  •