Selectors, Properties, and Values: Basic CSS Concepts
Last edited by admin Wed, 10/03/2012 - 20:14

 

The basic structure of an CSS declaration

Every CSS document is composed of many CSS declaration that follow the same syntax. It is of the form:

Selector {property: value}

Selectors

Selectors can be page elements, div elements, or class elements. Page elements can be recognized by the absence of any symbol before the element's name. Divs are written as #div_name, and classes as .class_name.
Example:

body
{
backround-color: red;
}

#div_name
{
font-color: green;
}

.class_name
{
line-height: 12px;
}

Properties

In the above example, backround-color, font-color and line-height are examples of properties that define the selectors.
For a full list of properties, see the CSS cheetsheat.

Values

The values for the properties from the example are obviously red, green, and 12px. Values for CSS properties can be hexadecimal notation for colors or the names of the colors, zero, or positive and negative integers for pixel and em values.