www.webdeveloper.com
Results 1 to 5 of 5

Thread: Class vs Id

  1. #1
    Join Date
    Dec 2002
    Location
    Malta
    Posts
    15

    Class vs Id

    Can someone me tell me please what exactly is the difference between a class and an id and when i should use which.

    Thanks

  2. #2
    Join Date
    Nov 2002
    Location
    England
    Posts
    275
    Use an ID when you want to apply style properties to one element only, use a class when you need it to be reusable, e.g.:

    Code:
    CSS:
    #menu { /*MENU object only*/
      position:absolute;
      top:0px;
      left:0px;
    }
    .center { /*For centering objects*/
      text-align:center;
    }
    
    HTML:
    <div id="menu">
      <h2>Blah</h2>
      <p class="center">Blah</p>
    </div>
    <p class="center">More blahs</p>

  3. #3
    Join Date
    Nov 2002
    Posts
    82
    IDs are useful if you wish to incorporate javascript as well. Check this explanation out:
    http://www.htmlgoodies.com/beyond/classid.html

  4. #4
    Join Date
    Nov 2002
    Location
    XYZZY - UK
    Posts
    1,760
    The "id" is a unique identifier and can only appear once within an XHTML document, the thing which makes attributes of type "id" special is that no two such attributes can have the same value; whatever the document language.

    Joe obviously doesn't completely understand the full functionally of the "id" he seems to think it doesn't do anything different than class within HTML which is wrong, you'd probably notice that it you tried a completely table-less design using CSS-P .

  5. #5
    Join Date
    Jun 2011
    Posts
    1
    hello, I`m new around here and trying to understand css...

    so in a website if i have let`s say 10 properties that i want to give to more than 1 object, i can put them all in 1 class and call that class whenever i want those properties?


    exactly, i have a right div=right bar, and inside i want 5 more div tags, each different, but they all have in common some properties. can i make then ID`s and inside each of them also call the same class?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles