0

Id and Class Selectors

when we setting a style for a HTML element, CSS allows to specify your own selectors called "id" and "class".

id Selector
The id selector is used to specify a style for a single, unique element.
The id selector uses the id attribute of the HTML element, and is defined with a "#".
The style rule below will be applied to the element with id="para1":

Example:
#paragr
{
text-align:center;
color:red;
}
Note: do not start an ID name with a number. Because It will not work in Mozilla/Firefox browser.

class Selector
The class selector is used to specify a style for a group of elements. Unlike the id selector.
This allows you to set a particular style for many HTML elements with the same class.
The class selector uses the HTML class attribute, and is defined with a "."
In the example below, all HTML elements with class="center" will be center-aligned:

Example:
.center {text-align:center;}
You can also specify that only specific HTML elements should be affected by a class.
In the example below, all p elements with class="center" will be center-aligned:

Example:
p.center {text-align:center;}
Note: Do not start a class name with a number! This is only supported in Internet Explorer.
Next
Newer Post
Previous
This is the last post.

Post a Comment

 
Top