Monday, October 11, 2010


IDs allow you to assign a unique identifier to an HTML element. This allows you to define a style that can only be used by the element you assign the ID to.

CSS ID Syntax
syntax of declaring id is same as class except that instead of using a dot, you use a hash (#).

#id-name { property:value; }

You should use IDs if only one element on the page should have the style applied, and/or you need a unique identifier for that element. For example, you might assign an ID to a div tag which contains your right menu. The styles for this ID could contain the position, font-color, float properties, font-size, height,background-color,width, etc. You probably wouldn't want any other element on the page to use this particular style.

CSS ID Example
<style type="text/css">
font-family:"Courier New", Courier, monospace;

font-family:Verdana, Arial, Helvetica, sans-serif;
<p id="section">This is Paragraph</p>
<p id="css-section">This is Paragraph2</p>

No comments:

Post a Comment