XML technologies / CSS / Advanced websites with CSS / CSS property reference / padding
(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)
The shorthand property padding describes the size of an element’s padding.
Padding lies between an element’s content and its border. The element’s background color or image also fills this area.
Padding can be declared separately for each side using the properties padding-bottom, padding-left, padding-right and padding-top.
Inherited: no
See also: padding-bottom, padding-left, padding-right, padding-top
Values
One to four values, separated by spaces (see the following table).
Each value can be a CSS measurement or a percentage of the parent element’s width or height.
Table: Value combinations for padding and their effects.
Number of values | Effect |
|---|---|
1 | The value applies to all four padding sides. |
2 | The first value applies to the horizontal top and bottom padding; the second to the vertical left and right padding. |
3 | The first value applies to top padding, the second to left and right padding, and the third to bottom padding. |
4 | The first value applies to top padding, the second to right padding, the third to bottom padding, and the fourth to left padding. |
Default value: 0
Compatibility
CSS version: 1
Works in all CSS-capable browsers, including Internet Explorer 4 and Netscape 4.
For bordered elements, Netscape 4 displays a three-pixel gap between border and padding. This cannot be removed and remains transparent even when the element has a background. The proprietary Netscape properties layer-background-color and layer-background-image fill this gap separately with the background color or image respectively.
Examples
The following style rule gives elements of the class warnung a thin border and red background. For whitespace inside the element, it also creates five pixels of top and bottom padding and ten pixels of left and right padding:
.warnung {
border: 1px solid;
background-color: red;
padding: 5px 10px;
}The following style rule creates three-pixel padding in every cell of a table of the class luftig, making it the CSS equivalent of the HTML attribute cellpadding.
table.luftig td, table.luftig th {
padding: 3px;
}
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