Home | Next Cascading Style Sheets

CSS Review

How to write CSS rules

A CSS rule is made up of a selector, and declarations, which are pairs of properties and values.

selector {property: value;
          property: value;
          property: value, value, value;
          }

The scope of the CSS rule (that is, which HTML elements should follow this rule) is set by the selector.

You can use HTML, class and ID selectors.

HTML SELECTORS

In the style sheet:

H3 {color: red;}

In the document:

<h3>Minor heading</h3>

CLASS SELECTORS

In the style sheet:

.funstuff {font-family: 'comic sans ms';}

P.funstuff {font-family: 'comic sans ms';}

In the document:

<p class="funstuff">
Here is some fun stuff...
</p>

ID SELECTORS

In the style sheet:

#area1 {margin-left: 10%; color: pink;}

In the document:

<div id="area1">
Bleeble blabble blooble blum...
</div>

Each ID may only be used once in a document.

Home | Next Cascading Style Sheets