The declaration
is made up of two subelements??”a
property and a value. p {color:red;}
property
selector declaration
value
Writing CSS Rules
This basic structure of the selector and the declaration can be
extended in three ways:
Multiple declarations can be contained within a rule.
p {color:red; font-size:12px; line-height:15px;}
Now our paragraph text is red, 12 pixels high, and the lines are 15
pixels apart. (Pixels are, of course, the tiny dots that make up your
screen display.)
Note that each declaration ends with a semicolon to separate it
from the next. The last semicolon before the closing curly bracket is
optional, but I always add it so that I can tack on more declarations
later without having to remember it.
Multiple selectors can be grouped. If, say, you want text for tags h1
through h6 to be blue and bold, you might laboriously type this
h1 {color:blue; font-weight:bold;}
h2 {color:blue; font-weight:bold;}
h3 {color:blue; font-weight:bold;}
and so on. But you can avoid this kind of repetition by grouping
selectors in a single rule like this
h1, h2, h3, h4, h5, h6 {color:blue; font-weight:bold;}
Just be sure to put a comma after each selector except the last. The
spaces are optional, but they make the code easier to read.
Multiple rules can be applied to the same selector. If, having written
the previous rule, you decide that you also want just the h3 tag
to be italicized, you can write a second rule for h3, like this
h1, h2, h3, h4, h5, h6 {color:blue; font-weight:bold;}
h3 {font-style: italic;}
CSS demands absolute accuracy; a
missing semicolon can cause CSS to
ignore an entire rule.
Pages:
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65