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.

The id selector is used to specify a style for a unique element, the id selector is defined with a #.
You can't start an id name with a number, it won't work in Firefox.

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.