XML technologies / XML / XML in a Nutshell / Cascading Style Sheets (CSS) / Colors
(Excerpt from "XML in a Nutshell" by Elliotte Rusty Harold & W. Scott Means)
CSS provides several properties for changing the colors of different components:
colorthe color of the text itself (black on this page)
background-colorthe background color behind the text (white on this page)
border-colorthe color of a visible box surrounding the text
CSS uses a 24-bit color space to specify colors, much like HTML. Remember, however, that specifying a color does not mean a particular device can display it. A monochrome printer will not print red, no matter how you specify the color; it will probably give you some pleasant shades of gray instead. Like many other properties, color depends on the medium in which the document is presented.
The easiest way to select a color is to use one of these 16 named constants: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white and yellow. Some colors are also defined by the colors of user interface components. For example, WindowText is the same color as the text in windows on the local system.
Beyond this short list, you can define an item’s color using the three components—red, green, and blue—as you probably know from HTML background colors. Each component is a number from 0 to 255, with 255 being the maximum intensity. The numbers can be decimal or hexadecimal. For example, these rules use hexadecimal notation to make the element gericht pure red, the element geschichte pure green, and the element anweisungen pure blue:
gericht { color: #FF0000 }
geschichte { color: #00FF00 }
anweisungen { color: #0000FF }If you prefer, you can specify the color as comma-separated decimal numbers inside an rgb( ) function. For example, white is rgb(255,255,255), black is rgb(0,0,0). Colors whose components all have the same value become shades of gray. These rules use decimal notation to display the element zutat in light gray and its child element menge in darker gray:
zutat { color: rgb(43,43,43) }
menge { color: rgb(21,21,21) }You can even specify each primary color as a percentage from 0 to 100 percent. The preceding rules would then look like this:
zutat { color: rgb(16.9%,16.9%,16.9%) }
menge { color: rgb(8.2%,8.2%,8.2%) }
Copyright © 2005 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from the book "XML in a Nutshell" is subject to the same conditions as the printed edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de
back to top