Monday, October 11, 2010

ID STYLES

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
<head>
<style type="text/css">
#section{
font-family:"Courier New", Courier, monospace;
font-size:12px;
color:#000000;
}

#css-section{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:10px;
color:#FF0000;
}
</style>
</head>
<body>
<p id="section">This is Paragraph</p>
<p id="css-section">This is Paragraph2</p>
</body>

No comments:

Post a Comment