XML technologies / CSS / Advanced websites with CSS / Adding some color / Transparency, color and user preferences
(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)
A trick lets us ensure that each individual element’s background color matches that of the element body. All we need is a style rule setting background-color to transparent. In this example, we create it for a class named transbox, since it can switch any box’s background color on the page to transparent:
.transbox {
color: white;
background-color: transparent;
}The property background-color also always defaults to transparent and is not inherited from the parent. A background image, for example, therefore need not be assigned separately to every element to appear continuously across the page.
However, when an element receives a colored background, it passes this property to all child elements. To prevent that for a particular element, simply assign it to the class defined by our style rule transbox. The inherited value is overridden and the background becomes transparent again down to the setting of body.
Background colors are particularly tricky when users set their own browser preferences, which simply disable all background colors and images. (Note: IE5 for Macintosh automatically overrides all style rules and HTML attributes with the user’s local stylesheet. IE6 for Windows does so only if the user creates a local stylesheet and explicitly gives it precedence. Netscape Navigator for Windows offers no way to create a local stylesheet, but does respect settings in an editable CSS file named ua.css. Netscape Navigator for Macintosh does not accept even this workaround and recognizes no local stylesheets at all.) Fortunately, few users change these preferences, so our pages’ CSS instructions normally take effect, and browser settings apply only to elements without CSS rules. Consider this example: the default background color is gray or white. If the background color of body is set to transparent, anything may happen. As the W3C specification explains, the output is undefined in such cases.
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
back to top