The Formal Style Property Specifications

We've seen quite a few CSS examples in this chapter. When you get more serious about CSS, you're going to need very in-depth information. For that reason, the rest of this chapter covers the most commonly used CSS styles and their formal specifications.

The World Wide Web Consortium (W3C) CSS style specifications give the possible values that CSS properties can take, the default value of those properties, and so on. The syntax that the W3C specifications use is a little complex. Here's an example: the style specification for the background- color property:

background-color

  • CSS1 values: <color>transparent

  • CSS2 values: inherit

  • Default value: transparent

  • Element support: All elements

  • Browser support: [IE4, IE5, IE6, NS4, NS6]

  • Style inherited: No

Here you can see the way a style is specified, listing the possible values that the property can take for the CSS1 level specification, as well as the possible values that CSS2 adds, the property's default value, which types of elements are supported (such as block-level elements), and whether the style is inherited by child elements. I'm also adding which of the two major browsers support the property and what versions of those browsers do.

Note the expression <color> transparent , which indicates the possible values you can assign this property. This expression means that you can set the background-color property to either a valid color value or the word transparent . The W3C syntax for style properties like this is worth getting to know so that you can refer to the W3C documentation when you need it. Here's the syntax the W3C uses:

  • Terms in angle brackets ( < and > ) specify valid units for values. See Table 9-1 for the details.

  • Values separated with specify alternatives. Only one alternative may be used.

  • Values separated with specify options. You can use one or more of them in any order.

  • Brackets ( [ and ] ) group statements. These are evaluated like mathematical statements.

  • A * means that the preceding term can occur zero or more times (as in DTD syntax).

  • A + means that the preceding term occurs one or more times (as in DTD syntax).

  • A ? means that the preceding term is optional (as in DTD syntax).

  • Curly braces ( { and } ) enclose a comma-separated pair of numbers giving the minimum and maximum number of times a term may occur, such as {0, 10} .

The expressions you see in angle brackets, such as <color> , use a specific format, and I list those formats in Table 9-1. For example, there you'll see that <color> can be set to a red, green, blue triplet color value or a predefined color. That means you could assign a color value to the background-color property like this in a style rule: {background-color: #0000ff} or {background-color: azure} .

Table 9-1. Units in the W3C Property Style Specifications
Unit Measurement Means
<absolute-size> Absolute font sizes. May be xx-small , x-small , small , medium , large , x-large , or xx-large .
<angle> Angle. May be deg , grad , or rad .
< border-style > Border style. May be none , dotted , dashed , solid , double , groove , ridge , inset , or outset .
< border-width > Width of a border. May be thin , medium , thick , or an explicit length.
<color> Color. May be specified with a predefined color value (theoretically one of the 16 predefined CSS colors but, in practice, any color name that the browser recognizes) or RGB triplet color value.
<family-name> Name of a font family, such as Times New Roman, Courier New, or Arial.
<frequency> Frequency values. Units may be Hz or kHz.
<generic-family> Generic names for fonts specified as a last resort if the browser can't find a specific font face. For example, you can set this type to serif (for a serif font), sans-serif (for a sans-serif font), or monospace (for a monospace font).
<generic-voice> Aural voices. May be set to male , female , or child .
<integer> Standard integer values.
<length> Length. Can start with + or - followed by a number. The number can include a decimal point and can be followed by a unit identifier, which may be em (font size of the relevant font), ex (the x height of the font), px (pixels), pt (points, 1/72 of an inch), in (inches), cm (centimeters), mm (millimeters), or pc (picas, 1/6 of an inch).
<number> Number. Can include a sign and a decimal point.
<percentage> Percentage. Can include a sign followed by a percent sign ( % ).
<relative-size> Font size relative to the parent element. Can be either larger or smaller.
<shape> Shape. Can be only a rectangle currently, like this: rect (<top> <right> <bottom> <left>) .
<time> Time units. Given as a number followed by ms ( milliseconds ) or s (seconds).
<uri> Uniform resource identifier.

You also should know about two special property values: auto and a new CSS2 value, inherit . You set a property to auto when you want the browser to assign an automatic value to the property. Usually, the value set depends on the context, such as the style or color of surrounding text. The inherit value is new in CSS2 and means that the value of this property should be inherited from its parent (instead of using the default initial value), if the element has a parent.

There's one more term to understand as well: box. A box is the area in which an element is drawn in the browser. That is, the box is the invisible rectangle surrounding the display area of the element. Because boxes are constructed with borders, padding, and margins, many style properties refer to them.

That's all the introduction we need to the actual style property specifications. I'll look at the most common style properties now, as well as the values they can take and what kind of elements you can use them with. Bear in mind that you can find the complete CSS property specifications at www.w3.org/TR/REC-CSS1 and www.w3.org/TR/REC-CSS2.

Style Properties

Another thing to keep in mind is that I'm listing the style properties as the W3C defines them here. The way your browser uses these style properties might differ .



Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net