< Day Day Up > |
Transitional versions of HTML and XHTML support color settings for text as well as for the background of the document, or even individual table cells . With style sheets, you will see that it is also possible to set both foreground and background color for nearly any element. There are 16 widely known color names defined in HTML. These names and their associated hex RGB values are shown in Table 6-2.
Black (#000000) | Green (#008000) |
Silver (#C0C0C0) | Lime (#00FF00) |
Gray (#808080) | Olive (#808000) |
White (#FFFFFF) | Yellow (#FFFF00) |
Maroon (#800000) | Navy (#000080) |
Red (#FF0000) | Blue (#0000FF) |
Purple (#800080) | Teal (#008080) |
Fuchsia (#FF00FF) | Aqua (#00FFFF) |
To set a particular section of text yellow, simply surround the content with <font color="yellow"> and </font> . Of course, in addition to the simple color names listed in Table 6-2, there are many others, some of which seem to have been introduced by the browser vendors ; these are listed in Appendix E. The problem with using browser-defined colors is that they don't always do what they are supposed to do. Even worse , you can invent your own colors. Try setting the following and viewing it under Netscape and Microsoft Internet Explorer:
<body bgcolor="html color names are troublesome">
This color name is totally invalid, but it still results in a shade of green that is very distinct in each browser. It is possible to make up colors like "chilidog brown" or "stale beer yellow," but this is no more recommended than using the browser-defined color of "dodgerblue." Using hex color values is the preferred way to set colors because some nonstandard color names are not supported correctly across browsers.
Instead of using color names, we ought to use values that represent the color that we want. To understand how to come up with a color value, first consider that a computer displays color using a combination of red, green, and blue. We call this additive color process RGB color. The easiest way to think of RGB color is as a set of three dials that control the amount of red, green, and blue mixed into the final color. Because of the way computers calculate things, the color values range from 0 to 255 in decimal or 00 to FF if we count in hexadecimal like a computer scientist. So a color specified by 0,255,0, or equivalently 00,FF,00, is equivalent to the green dial turned all the way up and the other dials turned off. This is a pure green. Equivalently, FF,00,00 is pure red. Finally, 00,00,FF is pure blue. Obviously, all dials off at 00,00,00 is the absence of color or simply black, whereas all dials on at FF,FF,FF is white. In HTML, we set these hex values using a pound sign and the equivalent RR, GG, and BB values are run together; for example, we could use the hex value #FFFF00 for the color attribute instead of the word "yellow."
Rather than becoming an expert at hexadecimal, it is easy to use a Web editor to pick a color or to see Appendix E, which explains the various colors available under HTML. A color reference can be found online at http://www.htmlref.com/colorchart.html.
< Day Day Up > |