Skip to Main Content
CSS: The Missing Manual
book

CSS: The Missing Manual

by David Sawyer McFarland
August 2006
Beginner to intermediate content levelBeginner to intermediate
496 pages
17h 36m
English
O'Reilly Media, Inc.
Content preview from CSS: The Missing Manual

Coloring the Background

It's a cinch to add a background to an entire page, an individual headline, or any other page element. Use the background-color property followed by any of the valid color choices described in Section 6.1.2. If you want, add a shockingly bright green to the background of a page with this line of code:

	body { background-color: #6DDA3F; }

Alternatively, you can create a class style named, say, .review with the background-color property defined, and then apply the class to the body tag in the HTML, like so: <body class="review">.

Note

You can also place an image in the background of a page and control that image's placement in many different ways. You'll explore that in the next chapter.

Background colors come in handy for creating many different visual effects. You can create a bold-looking headline by setting its background to a dark color and its text to a light color. (You'll see an example of this "reverse type" effect in the tutorial in Section 7.7.3.) Background colors are also a great way to set off part of a page like a navigation bar, banner, or sidebar.

Tip

When you use background colors and borders, keep the following in mind: If the border style is either dotted or dashed (see Figure 7-7), the background color shows in the empty spaces between the dots or dashes. In other words, Web browsers actually paint the background color under the borderline.

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.
Start your free trial

You might also like

CSS: The Missing Manual, 2nd Edition

CSS: The Missing Manual, 2nd Edition

David Sawyer McFarland
JavaScript: The Missing Manual

JavaScript: The Missing Manual

David Sawyer McFarland

Publisher Resources

ISBN: 0596526873Supplemental ContentErrata Page