Chapter 8. Backgrounds
By default, the background area of an element consists of the content box, padding box, and border box, with the borders drawn on top of the background. (You can change that to a degree with CSS, as you’ll see in this chapter.)
CSS lets you apply one solid opaque or semitransparent color to the background of an element, as well as apply one or more images to the background of a single element, or even describe your own color gradients of various shapes to fill the background area.
Setting Background Colors
To declare a color for the background of an element, you use
the property background-color, which accepts any
valid color value.
If you want the color to extend out a little bit from the content area of the element, add some padding to the mix, as shown in the following code and illustrated in Figure 8-1:
p{background-color:#AEA;}p.padded{padding:1em;}
<p>A paragraph.</p><pclass="padded">A padded paragraph.</p>
Figure 8-1. Background color and padding
You can set a background color for any element, from <body>
all the way down to inline elements such as <em> and <a>.
The value of background-color is not inherited.
Its default value is the keyword transparent, which should make sense: if an element ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access