我想知道爲什麼在<div>
中有內容(段落等)時出現margin
?爲什麼Div內容裏有自動保證金?
.container {
width: 300px;
height: 150px;
background-color: #ccc;
}
.container2 {
width: 300px;
height: 150px;
background-color: #000;
}
<div class="container">
<p>Text</p>
</div>
<div class="container2">
<p>Text</p>
</div>
在上面的示例中,存在兩個<div>
s之間的裕度,但如果我取出段,將margin
不見了。
這是怎麼發生的?
段落內置保證金和保證金摺疊。 –