这是我在网页上设置背景所做的:
body {
height: 100vh;
background: linear-gradient(white, tan);
}
<h1>Heading</h1>
<p>Paragraph</p>
两个问题:
- 为页面添加背景是否正确?
- 我应该如何摆脱不需要的滚动条?
最佳答案
body 标签的上、下、左、右默认边距为 8px。和 h1 标签默认 margin-top 和 margin-bottom 21.440px 或 0.67em 所以你需要设置 body margin:0 和 h1 margin:0 or margin-top:0
如果你只想为整个 body 设置背景颜色,那很好。如果您想了解有关背景属性的更多信息,请阅读此 CSS background Property
body {
height: 100vh;
background: green;
margin:0;
}
h1{
margin-top:0;
}
<h1>Heading</h1>
<p>Paragraph</p>
关于html - body 高度为 100vh 时的额外滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42980139/