在为html设置背景时,它将应用于所有四个边框。如果你只想在顶部网站上添加背景颜色,可以将一个 div
元素添加到DOM中,在页面上方显示:
<div style="height:1000px;background:#00BD9C;margin-top:-1000px;position:fixed;width:100%;"></div>
这样,溢出颜色只会应用在顶部。
或者您也可以纯粹使用CSS进行添加:
html:before {
content: '';
position: fixed;
width: 100%;
height: 999px;
top: -999px;
background-color: tomato;
}
margin-top: -999px
,这会使一个像素的线条可见...然后使用z-index: -1
将其移除。 - Abhi Beckert