You may remember from
our discussion on the document hierarchy in Chapter 1 that the
body tag is the great-ancestor of them all??”all CSS-targeted tags in
your markup descend from it. So thanks to the power of CSS inheritance,
if you style the body tag like this
body {font-family: verdana, helvetica, sans-serif; color:
blue;}
then the text of every text element in your entire document inherits
these styles and displays in blue Verdana (or in one of the other
choices if Verdana is not available), no matter how far down the
hierarchy it is. The ef?¬? ciency is obvious; rather than specify the
desired font for every tag, you set it once in this way as the primary
font for the entire site. Then you only need font-family properties
for tags that need to be in a different font.
Many CSS properties are inherited in this way, most notably text
attributes. However, many CSS properties are not inherited because
inheritance doesn??™t make sense for them. These properties primarily
relate to the positioning and display of box elements, such as
borders, margins, and padding. For example, imagine that you want
to create a sidebar with text in it. You might do this by writing a div
(which you can think of as a rectangular box), which has a list of
links inside it, and styling the div with a border, say a two-pixel red
line. However, it makes no sense for every one of those list items
within the div to automatically get a border too.
Pages:
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89