<p> 内部<div>的奇怪行为

  • 本文关键字:内部 div html
  • 更新时间 :
  • 英文 :


当我在div中放入一个p时,/div后面会出现一个额外的空行。更奇怪的是,如果我在div中使用填充,那么在结束/div之前会出现额外的空行。这显示在所有主要浏览器中。一个建议是填充p标签导致了这种情况,但p上没有样式。测试代码:

body {
background-color: pink;
}
.whitebox {
background-color: white;
}
.whitebox2 {
padding: 10px;
background-color: white;
}
<div class="whitebox">
Here is some text inside of the whitebox div.
</div>
More text here outside of div.
<div class="whitebox">
Here is more text in a new whitebox div.
<p>
Here is the 2nd paragraph in the div.
</div>
Yet more text outside of div.
<div class="whitebox2">
Here is text in a whitebox2 div.
<p>
Here is the 2nd paragraph in the div.
</div>
And some final text here.

<div class="whitebox">
Here is more text in a new whitebox div.
<p>
Here is the 2nd paragraph in the div.
</div>

您似乎在两个实例中都没有关闭p标签的</p><p> ... </p>是一个成对的元素,只有在按其语法使用时才会起作用。

我发现了一个破解方法来修复这个和其他崩溃的保证金问题。对于我目前的问题,我只是添加了p{margin-bottom:0;}到我的.css,问题就消失了。

同样,关闭p没有起作用。

最新更新