【发布时间】:2020-11-06 11:42:51
【问题描述】:
Chrome 和 Firefox 都有这个问题
我有一个不应随页面滚动的移动侧边栏。基本上是这样的:
body{
font-size: 16px;
width: 100vw;
height: 200vh;
background-color: orange;
}
.sideBar{
height: 100vh;
position: fixed;
background-color: blue;
left: 0;
top: 0;
width: 10rem;
}
/* media query for desktop. change the min-width */
@media screen and (min-width: 450px){
.sideBar{
position: static;
height: 20vh;
}
}
<!DOCTYPE html>
<html>
<head></head>
<body>
<div class="sideBar">
Hello
</div>
</body>
</html>
当我将窗口调整为窄尺寸时,它按预期工作。侧边栏不随页面滚动。但是当我点击移动模型按钮时,position: fixed 不再起作用。
我部署并检查了我的手机,侧边栏随着我的手机滚动。所以这不仅仅是浏览器模型的问题。
问题演练:
- 调整浏览器大小。
position: fixed仍然有效。请注意顶部的徽标是如何裁剪的,这意味着我向下滚动。实际上,我可以使宽度变得非常窄,并且在不滚动侧边栏的情况下滚动很远。
- 点击模型窗口后
-
position: fixed不再起作用,侧边栏随页面滚动。
【问题讨论】:
标签: html css position css-position