Set the bottom margin for a <p> element to 25 pixels:
p.ex1 {
margin-bottom: 25px;
}
Try it Yourself »
More "Try it Yourself" examples below.
The margin-bottom
property sets the bottom margin of an element.
Note: Negative values are allowed.
Default value: | 0 |
---|---|
Inherited: | no |
Animatable: | yes, see individual properties. Read about animatable Try it |
Version: | CSS1 |
JavaScript syntax: | object.style.marginBottom="100px" Try it |
The numbers in the table specify the first browser version that fully supports the property.
Property | |||||
---|---|---|---|---|---|
margin-bottom | 1.0 | 6.0 | 1.0 | 1.0 | 3.5 |
margin-bottom:
length|auto|initial|inherit;
Value | Description | Demo |
---|---|---|
length | Specifies a fixed bottom margin in px, cm, em, etc. Default value is 0. Negative values are allowed. Read about length units | Demo ❯ |
% | Specifies a bottom margin in percent of the width of the containing element | Demo ❯ |
auto | The browser calculates a bottom margin | Demo ❯ |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
Top and bottom margins of elements are sometimes collapsed into a single margin that is equal to the largest of the two margins.
This does not happen on horizontal (left and right) margins! Only vertical (top and bottom) margins!
Look at the following example:
In the example above, the <p class="a"> element has a top and bottom margin of 30px. The <p class="b"> element has a top and bottom margin of 20px.
This means that the vertical margin between <p class="a"> and <p class="b"> should be 50px (30px + 20px). But due to margin collapse, the actual margin ends up being 30px!
Set the bottom margin for a <p> element to 10% of the width of the container:
p.ex1 {
margin-bottom: 10%;
}
Try it Yourself »
Set the bottom margin for a <p> element to 2 em:
p.ex1 {
margin-bottom: 2em;
}
Try it Yourself »
CSS tutorial: CSS Margin
HTML DOM reference: marginBottom property
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!