Reputation: 550
This issue is on both Chrome and Firefox
I have a mobile-only sidebar that shouldn't scroll with the page. It's basically like:
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>
It works as expected when I resize the window to a narrow size. The side bar doesn't scroll with the page. But when I click on the mobile mockup button, the position: fixed
doesn't work any more.
I deployed and checked on my phone, and the sidebar scrolls with my phone. So it's not just a browser mock-up problem.
position: fixed
still works. Notice how the logo on top is cropped which means I scrolled down. I can actually make the width really narrow and scroll pretty far without scrolling the sidebar.position: fixed
doesn't work any more and the sidebar scrolls with the page.Upvotes: 4
Views: 3083
Reputation: 550
This is kind of late but I solved it a while back adding this line to the <head>
of the html document
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1"/>
seems the minimum-scale-1
is the crucial part.
Upvotes: 14
Reputation: 410
The problem, if I understood the explanation correctly, seems to come from width: 100vw
on body. Does removing it fix the problem?
Upvotes: 0