XML technologies / CSS / Advanced websites with CSS / CSS property reference / background-color
(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)
The property background-color sets the background color of an HTML element.
The default is always transparent. Since background-color is not inherited, child elements automatically have transparent backgrounds. Parent elements’ background colors or images therefore remain visible unless background-color is overridden by child elements’ own style rules.
Whenever you define a background color, also define the text color, and vice versa. This prevents problems caused by users’ browser settings.
Inherited: no
See also: color
Values
Any CSS color value (see CSS color reference) or transparent.
Default value: transparent
Compatibility
CSS version: 1
Works in all CSS-capable browsers, including Internet Explorer 4 and later and Netscape 4 and later.
Netscape 4 does not fill an entire block element with the background color unless a border (border) is also explicitly defined (a border value with a width of 0px is sufficient). If a visible border exists, a transparent gap remains between the padding and the border. Netscape’s proprietary property layer-background-color can fill this gap separately with the background color.
Example
The following style rule gives all elements blockquote a tomato-red background. Declaring a border with width 0 makes Netscape 4 display the background color across the entire block element as well.
blockquote {
background-color: #ff6347;
border: 0 solid #ff6347;
}
Copyright © 2006 of the German translation, dpunkt.verlag GmbH
You may print the online version for your private use.
Otherwise, this chapter from “CSS − Anspruchsvolle Websites mit Cascading Stylesheets” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
dpunkt.verlag GmbH, Ringstraße 19, 69115 Heidelberg