该属性用于设置元素的底部外边距,可设置负数值。 该属性对设置了 non-replaced 的行内元素无作用,例如: <tt> 或 <span>.
/* <length> value */ margin-bottom: 2.5em; /* <percentage> value */ margin-bottom: 95%; /* Keyword values */ margin-bottom: auto;
| 值 | 描述 |
|---|---|
| <length> | 此关键词定义了一个确定的宽度值。 |
| <percentage> | 此关键词表示 <percentage> 始终同包含该元素的容器宽度有关。 |
| auto | 此关键词会被替换为一个适当的值。且可以用于讲一个块级元素居中。参考margin |
HTML
<div id="red"> <div id="orange"></div> <div id="gray"></div> </div>
CSS
#red {
width: 200px;
height: 200px;
background: red;
}
#orange {
width: 50px;
height: 50px;
background: orange;
margin-bottom: 30px;
}
#gray {
width: 50px;
height: 50px;
background: gray;
}
执行结果