XML technologies / CSS / Advanced websites with CSS / Behind the scenes / Using shorthand properties
(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)
Most CSS properties receive individual values. When several values are defined for one property, such as alternative typefaces for font-family, separate them with commas. A value name containing spaces or CSS syntax characters, such as a semicolon or colon, must be quoted.
There are also shorthand properties (English: shorthand property), which define several CSS properties in one property definition. This sounds more complicated than it is.
The best-known shorthand property is font. CSS beginners usually define one font property after another:
h1 {
font-weight: bold;
font-size: 90%;
line-height: 1.8em;
font-family: Helvetica, Arial, sans-serif;
}The shorthand CSS property font defines all these font properties more efficiently:
h1 {
font: bold 90%/1.8em Helvetica, Arial, sans-serif;
}The same approach works for the property padding:
h1 {
padding-top: 10px;
padding-right: 20px;
padding-bottom: 10px;
padding-left: 5px;
}We can replace this definition with the following shorthand:
h1 {
padding: 10px 20px 10px 5px;
}Values are given clockwise: top, right, bottom, then left.
All CSS shorthand properties are listed in CSS property reference.
Copyright © 2006 of the German translation, dpunkt.verlag GmbH
You may print the online version for your private use.
Otherwise, this chapter from “CSS − Anspruchsvolle Websites mit Cascading Stylesheets” 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.
dpunkt.verlag GmbH, Ringstraße 19, 69115 Heidelberg
back to top