The CSS reference
"padding" - css property (v. css 1)
- The 'padding' property is a shorthand property for setting 'padding-top' , 'padding-right' , 'padding-bottom' and 'padding-left' at the same place in the style sheet.
- If four values are specified they apply to top, right, bottom and left respectively.
- If there is only one value, it applies to all sides.
- If there are two or three, the missing values are taken from the opposite side.
- Initial value: See individual properties
- The property is not inherited
- HTML usage: All elements except table-row-group, table-header-group, table-footer-group, table-row, table-column-group and table-column
-
Browsers that support the padding - property :
How width, height, margin, border and padding properties relates to each other:
• 'margin-top'
• 'margin-bottom'
• 'margin-left'
'margin-right'
•
• 'border-top-width'
• 'border-bottom-width'
• 'border-left-width'
'border-right-width'
•
-
The total element width is calculated as:
'margin-left' + 'border-left-width' + 'padding-left' + 'width' + 'padding-right' + 'border-right-width' + 'margin-right' -
The total element height is calculated as:
'margin-top' + 'border-top-width' + 'padding-top' + 'height' + 'padding-bottom' + 'border-bottom-width' + 'margin-bottom'
Possible padding values:
padding value | Comments | CSS |
---|---|---|
length | With this you specify a positive value followed with a unit identifier (it cannot be negative as for the margin). | 1 |
percentage | With this you specify a value with a percentage. It refer to width of containing block. | 1 |
inherit | Will inherit the value from parent specification. This property value is new with CSS 2. | 2 |
Possible unit identifier:
unit identifier | Comments | CSS |
---|---|---|
em | The relative unit 'em' is relative to the font size of the element itself. | 1 |
ex | The relative unit 'ex' is relative to the font size of the element itself. | 1 |
px | Pixels, relative to the viewing device | 1 |
in | inches -> 1 inch is equal to 2.54 centimeters. | 1 |
cm | centimeters. | 1 |
mm | millimeters. | 1 |
pt | points -> the points used by CSS2 are equal to 1/72th of an inch. | 1 |
pc | picas -> 1 pica is equal to 12 points. | 1 |
Property "padding" example:
<!DOCTYPE HTML >
<html >
<head>
<title>Test</title>
<style type="text/css">
.presentation {
border-color: #aad5ff;
border-style: solid; }
table.presentation {
border-width: 0 0 1px 1px;
width: 500px; }
th.presentation, td.presentation {
border-width: 1px 1px 0 0;
padding: 4px 4px 4px 4px; }
th.presentation { background-color: #D4FFAA;}
</style>
</head>
<body>
<table class='presentation' border='0'
cellpadding='0' cellspacing='0' >
<tr>
<th class='presentation' style="width: 22%">Values</th>
<th class='presentation'>Comments</th>
<th class='presentation'>CSS</th>
</tr>
<tr>
<td class='presentation'>thin, medium or thick</td>
<td class='presentation'>The width of the keyword
values are UA dependent,
but the following holds: <b>'thin' <= 'medium'
<= 'thick'</b>. </td>
<td class='presentation'>1</td>
</tr>
<tr>
<td class='presentation'>length</td>
<td class='presentation'>With this you specify a
value with a <b>unit identifier</b>. </td>
<td class='presentation'>1</td>
</tr>
<tr>
<td class='presentation'>inherit</td>
<td class='presentation'>Will inherit the value from
parent specification. This property value is new
with CSS 2.</td>
<td class='presentation'>2</td>
</tr>
</table>
</body>
</html>
Javascript access:
// To SET values ([o] is the target object)
[o].style.padding="padding values"
// You can not retrieve values through this property
// To get values, look at each of the padding properties.
© 2010 by Finnesand Data.
All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the
correctness in the pages or source codes.
The risk of using this web-site pages or any program
codes from this website is entirely at the individual user.