Monday, October 4, 2010

IDs in Css

An ID can only be used once per page, and is a unique identifier to an element. Typically, an
ID is used for any unique page element such as the header, main navigation, footer, or other
key part of the user interface.


Applying an ID
The most common way to apply an ID is to reference it in the (X)HTML using the id="name"
attribute immediately after the opening tag within an element. In this case, our two IDs are
named highlight and default, respectively, and are applied to two paragraphs:
<p id="highlight">This paragraph has red text.</p>
<p id="default">This paragraph has dark gray text.</p>
The corresponding CSS uses the hash (#) character to denote the rule is a unique ID. The
hash is combined with the ID name to start the rule, followed by the property declarations:
/* Define highlighted text */
#highlight {
color:#F00;
}
/* Define default text */
#default {
color:#333;
}

No comments:

Post a Comment