Ultimate CSS Reference

Page 42

26

The Ultimate CSS Reference

@import url(base.css);

Rule Sets A rule set (also called a rule) comprises a selector (p. 26) followed by a declaration block (p. 28); the rule set applies the declarations listed in the declaration block to all elements matched by the selector. Here’s an example of a rule set: h2 {

color: #666;

font-weight: bold;

}

Selectors A selector comprises every part of a rule set (p. 26) up to—but not including—the left curly brace {. A selector is a pattern, and the declarations (p. 28) within the block that follows the selector are applied to all the elements that match this pattern. In the following example rule set, the selector is h2: h2 {

color: #666;

font-weight: bold;

}

This selector—which is comprised of a single simple selector—will match all elements of type h2 in an HTML document. A simple selector can either be an element type selector (p. 62) or the universal selector (p. 60), (*), optionally followed by attribute selectors (p. 67), ID selectors (p. 65), or pseudo-classes (p. 80).1 A selector can comprise a number of simple selectors separated by combinators (p. 73),

1

Note that in CSS3, simple selectors are defined slightly differently than they are in CSS2.1. See Selector Reference (p. 59) for details.


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.