Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Body set to overflow-y:hidden but page is still scrollable in Chrome

I'm having an issue with the overflow-y property in Chrome. Even though I've set it to hidden, I can still scroll the page with the mouse wheel.

Here is my code:

html,  body {    overflow-y: hidden;  }    #content {    position: absolute;    width: 100%;  }    .step {    position: relative;    height: 500px;    margin-bottom: 500px;  }
<body>    <div id="content">      <div class="step">this is the 1st step</div>      <div class="step">this is the 2nd step</div>      <div class="step">this is the 3rd step</div>    </div>  </body>

Does anybody know how to block the vertical scrolling in Chrome?

Thanks!

like image 221
Cécile Boucheron Avatar asked Oct 07 '13 23:10

Cécile Boucheron


People also ask

Does overflow hidden prevent scrolling?

To hide the horizontal scrollbar and prevent horizontal scrolling, use overflow-x: hidden: HTML.

Why does overflow hidden not work?

It is because you are using position absolute. You cannot use position absolute with overflow hidden, because position absolute moves the targeted element out of context with the document structure.

How do I stop my body from scrolling?

Disabling scroll with only CSS. There's another way to disable scrolling that is commonly used when opening modals or scrollable floating elements. And it is simply by adding the CSS property overflow: hidden; on the element you want to prevent the scroll.


1 Answers

Setting a height on your body and html of 100% should fix you up. Without a defined height your content is not overflowing, so you will not get the desired behavior.

html, body {   overflow-y:hidden;   height:100%; } 
like image 62
RhinoWalrus Avatar answered Sep 24 '22 05:09

RhinoWalrus