398 Chapter 23 – Cascading Style Sheets
Specifying Values
Web Design in a Nutshell, eMatter Edition
an HTML element as it is displayed in the browser window. The following code
adds extra letter spacing in the first line of text for every paragraph:
P:first-line { letter-spacing: 6pt }
Pseudo-elements can be combined with class information, so you can apply first-
line or -letter effects to only a certain class of element. The following sample
makes the first letter of any paragraph classified as “opener” big and red:
P.opener:first-letter { font-size: 300%; color: red }
Pseudo-classes
CSS1 provides pseudo-classes, which can be applied to the anchor (<a>) tag:
link,visited, andactive(referring to the various link states as interpreted by
the browser). These do not apply to named anchors, only those containing the
HREF attribute.
A:link { color: red }
A:visited { color: blue }
A:active { color: maroon }
This style information provides the same functionality as specifying link colors in
the<body> of a document, however, it has the advantages that style sheets
provide. Netscape’s support for pseudo-classes is pretty buggy.
Specifying Values
It is important to use the proper syntax for specifying length and color values in
style sheet rules.
Length Units
Table 23-1 lists units of measurements that can be specified in style sheet values.
Table 23-1: Units of Measurements for Style Sheet Values
Code Unit Description
px Pixel Pixel units are relative to the monitor resolution.
pt Point A traditional publishing unit of measurement for type.
There are approximately 72 points in an inch.
pc Pica A traditional publishing unit of measurement equal to 12
points (or 1/6 of an inch).
em Em A relative unit of measurement that traditionally equals
the width of the capital letter M in the current font. In
practical terms, it is equal to the point size of the font
(e.g., an em space in 24pt type is 24 points long).
ex Ex A relative unit of measurement which is the height of the
letter “x” for that font (approximately half the length of
an Em).
in Inches Standard unit of measurement in the U.S.
mm Millimeters Metric measurement.
cm Centimeters Metric measurement.