What is the difference between class="" and id=""?
What is the difference between class="" and id=""?
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!
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.
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!
Hey thanks Twey.....![]()
This is surely going to help me.
Bookmarks