XML technologies / CSS / CSS Cookbook / General topics / Shorthand properties
(Excerpt from “CSS Kochbuch” by Christopher Schmitt)
Problem
You want to combine declarations for individual properties using shorthand properties.
Solution
Start with a correctly marked-up HTML section:
<h3>Kurzschrift-Eigenschaften</h3>
<p>Mit Hilfe von Kurzschrift-Eigenschaften können Sie sich einiges an Tipparbeit sparen und gleichzeitig die Dateigröße klein halten. Außerdem können Sie auf diese Weise die Leserlichkeit Ihrer Stylesheets erhöhen.</p>Instead of separate rules for the properties font-style, font-size and font-family, combine them in the shorthand property font:
h3 {
font: italic 18pt verdana, arial, sans-serif;
}
p {
border: 2pt solid black;
}Discussion
Many individual CSS properties can be combined using so-called shorthand properties.
For example, border is a shorthand property combining the rules for the following three properties:
border-colorborder-widthborder-style
The shorthand property font also combines several properties. Values can be specified for the following individual properties:
font-stylefont-size/line-heightfont-familyfont-weightfont-variant
Apart from font-family and font-size/line-height, specify values as you would for the individual properties. The values for font-family must, when using font, be listed in order of priority and separated by commas.
If you want to specify values for both font-size and line-height, separate them with a slash:
h3 {
font: italic 18pt/20pt verdana, arial, sans-serif
}The following table lists the available shorthand properties.
Table: Shorthand properties.
Property | Value | Example |
|---|---|---|
|
|
|
|
|
|
|
| |
|
| |
| ||
| ||
|
|
|
|
|
|
|
|
|
|
|
|
See also
The CSS 2.1 specification on border shorthand properties and
; a complete list of CSS properties is also available under CSS 2.1: properties and proprietary extensions.
Copyright of the German edition © 2007 by O’Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “CSS Kochbuch” 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.
O’Reilly Verlag GmbH & Co. KG, Balthasarstr. 81, 50670 Köln