Property: |
margin |
Values: |
<length>, <percentage>, auto |
Initial: |
not defined for shorthand properties |
Inherited: |
no |
The 'margin' property is a shorthand property for setting 'margin-top',
'margin-right', 'margin-bottom' and 'margin-left' at the same place in the style
sheet.
If four length 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.
BODY { margin: 2em } /* all margins set to 2em */
BODY { margin: 1em 2em } /* top & bottom = 1em, right & left = 2em */
BODY { margin: 1em 2em 3em } /* top=1em, right=2em, bottom=3em, left=2em */
The last rule of the example above is equivalent to the example below:
BODY {
margin-top: 1em;
margin-right: 2em;
margin-bottom: 3em;
margin-left: 2em; /* copied from opposite side (right) */
}
Negative margin values are allowed, but there may be implementation-specific
limits.
Property: |
margin-bottom |
Values: |
<length>, <percentage>, auto |
Initial: |
0 |
Inherited: |
no |
This property sets the bottom margin of an element:
H1 { margin-bottom: 3px }
A negative value is allowed, but there may be implementation-specific limits.
Property: |
margin-left |
Values: |
<length>, <percentage>, auto |
Initial: |
0 |
Inherited: |
no |
This property sets the left margin of an element:
H1 { margin-left: 2em }
A negative value is allowed, but there may be implementation-specific limits
Property: |
margin-right |
Values: |
<length>, <percentage>, auto |
Initial: |
0 |
Inherited: |
no |
This property sets the right margin of an element:
H1 { margin-right: 12.3% }
A negative value is allowed, but there may be implementation-specific limits.
Property: |
margin-top |
Values: |
<length>, <percentage>, auto |
Initial: |
0 |
Inherited: |
no |
This property sets the top margin of an element:
H1 { margin-top: 2em }
|