Friday, August 19, 2011

CSS3 Tutorial 2: id and class Selectors

Along with setting styles for HTML elements, you can also specify your own selectors called id and class.

id
The id selector is used to specify a style for a unique element, the id selector is defined with a #.
#paragraph
{
text-align:left;
color:yellow;
}
You can't start an id name with a number, it won't work in Firefox.

class
The class selector is used to specify the style for a group of elements. The class selector is commonly used on multiple elements, This lets you set a style for many HTML elements with the same class. The class selector is defined with a '.'
In this example, all HTML elements with class="center" will be center-aligned:
.center {text-align:center;}
As with id, don't start a class with a number, this is only supported in Internet Explorer.

2 comments: