What si the difference between id and class

Discussion in 'CSS' started by arcguy, May 20, 2007.

  1. #1
    I searched many times but still cant understand the difference between div and class use in css
    Please any one tell my easy and effective way?
     
    arcguy, May 20, 2007 IP
  2. Leox Adir

    Leox Adir Guest

    Messages:
    237
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    in the .CSS file you put .name when you use class and #name when you use ID.
    I don't think there's any difference in the way of using them.
    I use class when I code with tables and if when I code with div's.
     
    Leox Adir, May 20, 2007 IP
  3. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #3
    There are very important differences. A class token points to any number of elements within a group. It's like saying everyone with blue eyes. In a practical sense, you might have a class called 'comment' on your blog page. You can style the <element class="comment"> and its descendants as a contextual block. You might want to make the text green without affecting other parts of the page. Simply style .comment p {color: green;}.

    The id token points only to one element. Like calling someone by name; only that one person answers. It is highly specific. When the style engine walks the DOM, it stops as soon as it finds its first instance of the id; since there can be only one, the style rules cannot be applied to any subsequent instances. Every class instance is located and styled.

    The real power of the id shows up when scripting against the DOM. You can use document.getElementById("token"), and your script knows exactly which element it is. There is no counterpart for classes. You must walk the DOM, searching for an element where element.class == "token". When you find one, it is just a member of an array of any number of elements with that class.

    Help some?

    cheers,

    gary
     
    kk5st, May 20, 2007 IP
  4. Leox Adir

    Leox Adir Guest

    Messages:
    237
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I didn't know that ^^
    Thanks,
    Leox
     
    Leox Adir, May 20, 2007 IP
  5. erotomania

    erotomania Banned

    Messages:
    291
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5

    i've been thinking of this before, there's a big diffrence between ID and Class but i don't have time to know it, so thank you very much for this.
     
    erotomania, May 20, 2007 IP
  6. ice26

    ice26 Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You can use class many times in different tags on your page, and only 1 time use id.
     
    ice26, May 21, 2007 IP
  7. arcguy

    arcguy Well-Known Member

    Messages:
    1,056
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    153
    #7
    what will happen if i use Id more then One time in a page?
    this is what i want to ask...
     
    arcguy, May 22, 2007 IP
  8. AdamSee

    AdamSee Well-Known Member

    Messages:
    422
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    135
    #8
    Your page won't validate, javascript may have problems and using the http://url.com#anchor won't work. It's not meant to be used more than once.
     
    AdamSee, May 23, 2007 IP