Results 1 to 5 of 5

Thread: Diff. class and id

  1. #1
    Join Date
    Jul 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Diff. class and id

    What is the difference between class="" and id=""?

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    In CSS terms, a class can be used as many times as you like whereas an ID can be used only once in any given page. IDs are also more specific than classes, so their rules will take precedence over those of the class.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jul 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi Twey.....

    Hey thanx for ur reply. Can u give me an example for the same or any good site where as I can find out as to how the same can be done.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <style type="text/css">
    .myclass {
      background-color: red;
    }
    
    #myid {
      background-color: blue;
    }
    </style>
    Code:
    <span class="myclass">
      <!-- This span has a red background. -->
    </span>
    
    <span id="myid" class="myclass">
      <!-- This span has a blue background, because the ID takes precedence -->
    </span>
    
    <span id="myid">
      <!-- This will probably show a blue background in a lot of browsers, but is erroneous and won't validate because the same ID has been used twice. -->
    </span>
    Last edited by Twey; 07-20-2006 at 12:22 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Jul 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hey thanks Twey.....

    This is surely going to help me.

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
  •