我想在向下滚动时修复元素的位置(.topsection)。桌面运行良好,但移动设备却隐藏了一半。
注意:在js中,在滚动事件上更改背景色的包装器需要一个带有.topSeg-容器类的元素。
HTML
<div class="topblock">
<div class="header">
<div class="topsection-container">
<div class="topsection">
`//some code...`
</div>
</div>
</div>
</div>
CSS
.topsection-container {
position: fixed;
width: 100vw;
left: 0;
z-index: 3;
transition: all .3s ease 0s;
}
.topsection {
position: fixed;
display: flex;
justify-content: space-between;
align-items: center;
padding: 1.5rem 10% 0 10%;
position: relative;
}
发布于 2020-12-28 14:22:51
position: fixed
在您的代码中运行良好,唯一的问题是body
在移动屏幕上向下滚动,这就是为什么.topsection-container
的一半向上滚动。body
有额外的滚动的东西,让他们滚动。
添加以下CSS并尝试:
html, body {
overflow: auto;
}
https://stackoverflow.com/questions/65478746
复制相似问题