16.7. Specifying ValuesIt is important to use the proper syntax for specifying length and color values in style sheet rules. 16.7.1. Length UnitsCSS allows measurements to be specified in a variety of units. Some of the units (such as em and pica) are taken from the traditional print publishing world. When specifying lengths, keep the following in mind:
Table 16-1 lists units of measurements that you can specify in style sheet values.
16.7.2. Specifying ColorAs in HTML, there are two methods for specifying color in style sheets: by name and by numerical value. 16.7.2.1. By nameYou can specify color values by name as follows: h1 {color: olive;} The CSS 2.1 specification accepts only 17 color names for use in style sheets (CSS 1 and CSS 2 had only 16 names; orange was added in Version 2.1.) The color names are:
Other names from the complete list of color names may be supported by some browsers. For the complete list, see Appendix D. 16.7.2.2. By RGB valueWithin style sheets, RGB colors can be specified by any of the following methods: {color : #0000FF;} {color: #00F;} {color: rgb(0,0,255);} {color: rgb(0%, 0%, 100%);} The first method uses three two-digit hexadecimal RGB values (for a complete explanation, see Appendix D). The second method uses a three-digit syntax, which is essentially converted to the six-digit form by replicating each digit (therefore, #00F is the same as #0000FF). The last two methods use a functional notation specifying RGB values as a comma-separated list of regular values (from 0 to 255) or percentage values (from 0 to 100%). Note that percentage values can use decimals, e.g., rgb(0%, 50.5%, 33.3%). 16.7.3. Percentage ValuesPercentage values are indicated by a number followed by the percentage sign (%). Percentage values are calculated relative to other values in the document. When specifying percentage values for measurements, it is important to pay attention to how they will be calculated for the given property. Sometimes percentages are relative to the current element. In other instances, they are calculated based on the properties of the parent element. The CSS Recommendation specifies how percentage values are calculated for each value, and there are notes provided in the descriptions in this book as necessary. 16.7.4. Keyword ValuesMost properties also have values that are described in keywords. You'll find keywords for each property in the property listing in the CSS Recommendation and throughout this book. Note that a keyword like normal may have different functions depending on the context of the property to which it is applied. All properties in CSS 2.1 have the keyword inherit that forces the value of the property to be the same as that of the parent element. Most properties inherit by nature, but the inherit keyword is a tool for overriding assigned styles when necessary. |