Step by Step

Monday, May 23, 2011

To be able to style an element on a page, a browser has to know three things:


What element of the page must be styled?
What part of that element must be styled?
How do you want that part of the selected element to look?
The answers to these questions are given by selectors, properties, and values.
Selectors
Used to select or point to one or more specific elements within your page.
The selector answers the first question: What element of the page must be styled?

Types OF CSS Selector:

1-The Universal Selector
Indicated by an asterisk (*), applies to all elements in your page.
The Universal selector can be used to set global settings like a font family.
*
{
font-family: Arial;
}
2-The Type Selector
Point to an HTML element of a specific type.
h1
{
color: Green;
}
This Type selector now applies to all

elements in your code and gives them a green color. Type selectorsare not case sensitive, so you can use both h1 and H1 to refer to the same heading.
3-The ID Selector
Always prefixed by a hash symbol (#) and enables you to refer to a single element in the page. Within an HTML or ASPX page, you can give an element a unique ID using the id attribute.
#IntroText
{
font-style: italic;
}
Because you can reuse this ID across multiple pages in your site (it only has to be unique within a single page)
ID selectors are case sensitive, so make sure that the id attribute and the selector always use the same casing.

0 comments: