【发布时间】:2013-06-15 17:55:34
【问题描述】:
为什么在div中h1、h2、h3元素的边距会被忽略?
<div class="col">
<h3>This is header</h3>
</div>
<div class="col">
<h3>This is header</h3>
</div>
.col {
background: gray;
margin-bottom: 1em;
}
.col h3 {
margin-bottom: 1em;
}
当我将 h 元素放入 div 并且其中没有其他文本时,虽然指定了 h 元素和 div 元素的底部边距,但忽略了 h 底部边距。
【问题讨论】:
-
这是正确的行为,你想要的是给你的
col类一个padding-bottom: 1em; -
我不确定您要做什么...但也许您正在尝试做填充:改为检查
padding-bottom: 1em;。 -
你尝试忽略下边距设置 margin-top:-18px;在 .col css 中