【发布时间】:2017-07-13 16:49:43
【问题描述】:
在 id 为“header”元素(第二个 div)的 div 之后有一些额外的空间。如果我删除 p,div 元素之间没有空格。如何在不删除 p 元素的情况下消除两个 div 元素之间的空间以及为什么它会这样?
body {
margin: 0px;
padding: 0px;
}
div#page {
width: 960px;
margin: 10px auto;
}
div#header {
width: 960px;
height: 80px;
background-color: lightgray;
}
div#main {
height: 400px;
width: 960px;
background-color: antiquewhite;
}
<div id="page">
<div id="header">header</div>
<div id="main">
<p>we make your business</p>
<p>Con panna organic americano grinder single origin white mug chicory arabica breve cortado. In sit, aromatic lungo shop body redeye.</p>
<form action="" method="post">
<button>about us</button>
</form>
</div>
</div>
【问题讨论】:
-
你需要明确哪个
div元素 -
给出写着“我们做你的生意”的div,
margin-top: 0 -
尝试使用 css 重置。
-
div#header { width: 960px; height: 80px; margin-bottom: -16px; background-color: lightgray; }