Wednesday, February 16, 2011

Difference between id and class in CSS div


Ids are to be used only once in your html layout. Ids are used for the main elements of the page, such as header, main content, sidebar, footer, etc. Ids have priority over classes. Ids start with # in css

Classes are used for elements that will appear several times on your page. Classes start with . in css

example:
<!--CSS part:-->
<style type="text/css">
#blueidstyle {color:blue}
.redclassstyle {color:red}
</style>
<!--HTML part:-->
<body>
<p id="blueidstyle">Blue for id</p>
<p class="redclassstyle">Red for class</p>
</body>

result:



Blue for id
Red for class

No comments:

Post a Comment