Web designers
?¬? nally have comprehensive control of the layout of their pages, without having
to resort to workarounds such as tables and spacer GIFs.
Anatomy of a CSS Rule
Let??™s start learning about how CSS is written by looking at a simple
CSS rule. For example, here??™s a rule that makes all text in all paragraphs
of your document red
p {color:red;}
So if you have this XHTML markup
This text is very important
then it will be red.
A CSS rule is made up of two parts: the selector, which states which
tag the rule selects, (or, as I like to say, which rule the selector targets)
??”in this case, a paragraph??”and the declaration, which states
what happens when the rule is applied??”in this case, the text displays
in red. The declaration itself is made up of two elements: a
property, which states what is to be affected??”here, the color of the
text??”and a value, which states what the property is set to??”here,
red. It??™s worth taking a good look at this diagram (Figure 2.2) so
that you are absolutely clear on these four terms; I??™ll be using them
extensively as we move forward.
While a p tag in the XHTML markup
is enclosed in angle brackets, in the
CSS style, you just write the tag name
without the angle brackets.
HOW CSS WORKS 33
FIGURE 2.2 There are two main
elements of a CSS rule??”a selector
and a declaration.
Pages:
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64