h1
元素會導致滾動條出現。任何人都能解釋我爲什麼?css:margin-top會導致滾動條
html, body {
margin: 0;
padding: 0;
height: 100%;
}
header {
height:10%;
}
section {
height:90%;
}
<header>
<h1>
Hello
</h1>
</header>
<section>
test
</section>
這實際上是最好的答案。但有些問題:如果我只有一個帶有邊距的元素,邊緣如何崩潰?其次,您在建議中建議哪種解決方案? – Matthew
我提到'margin-bottom',因爲在很多(大多數?)情況下,會有'h1'下面的元素。我假設的問題提供了一個非常簡化的例子。在實際使用中,「margin-bottom」可能會產生影響。但我同意在這種情況下只有'margin-top'很重要。 –
@Mthethew如果你不需要保證金,我會刪除它。否則,我會使用'h1 {display:inline-block}'或類似的命令來防止邊距崩潰。 – Oriol