Latest web development tutorials

CSS Id and Class selectors

id and class selectors

If you want to set CSS styles in HTML elements, you need to set the "id" and "class" selector element.


id selector

id selector may be labeled with a specific id of the HTML element specifies a particular style.

HTML elements with the id attribute set id selectors, CSS id selector to the "#" is defined.

The following rules apply to the style element attribute id = "para1":

Examples

#para1
{
text-align:center;
color:red;
}

try it"

Remark ID attributes do not start with a number, the ID number at the beginning does not work in Mozilla / Firefox browser.


class selector

Style class selector is used to describe a group of elements, class selector Unlike id selector, class can be used in more than one element.

class selector in HTML class attribute to indicate, in CSS class selector to a Point Number displayed. "":

In the following examples, all have a center like HTML elements are centered.

Examples

.center {text-align:center;}

try it"

You can also specify a particular HTML element uses class.

In the following examples, all of the p element uses class = "center" so that the text of the element of the center:

Examples

p.center {text-align:center;}

try it"

Remark The first character class name can not use digital! It can not work with Mozilla or Firefox.