我无法让背景随用户滚动。我希望顶部的 12% 为白色,底部的 6% 为白色,屏幕的其余部分为蓝色。我希望顶部的白色仅在用户位于页面顶部时显示,而底部的白色仅在用户位于页面底部时显示。
如有任何帮助,我们将不胜感激。
<body>
<div id="bg-top"></div>
</body>
<style>
body {
background-color: #ffffff;
position: scrolling;
}
#bg-top {
background-color: #00b9ff;
position: scrolling;
top: 12%;
position: fixed;
bottom: 6%;
left: 0%;
right: 0%;
z-index: -1;
}
</style>
最佳答案
您需要使用位置 absolute 而不是像这样的 fixed :
为了更好地查看结果,我在 body 的高度上设置了一个很大的值
body {
margin:0;
padding:0;
background-color: #ffffff;
position: relative;
min-height:1000px;
}
#bg-top {
background-color: #00b9ff;
top: 12%;
position: absolute;
bottom: 6%;
left: 0%;
right: 0%;
z-index: -1;
}
<div id="bg-top"></div>
关于html - 让页面背景随用户滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47376910/