2

Can someone please run this?

<html>

    <body style="overflow: hidden;">

        top

        <div style="background-color: red; height: 2000px;"></div>

        bottom

    </body>

</html>

Using Chrome version 36.0.1985.143 m on Windows, I can still scroll. Using Chrome on Mac OS X, Firefox and IE11, I can't.

6
  • If you don't want the page to be able to scroll, try using html {overflow: hidden}. Otherwise, explain better your problem.
    – Frondor
    Commented Aug 25, 2014 at 4:40
  • That's my goal, yes. Tried it. No effect sadly.
    – S. Valmont
    Commented Aug 25, 2014 at 4:40
  • checked in chrome Version 36.0.1985.143 m and cannot scroll the page. check link. jsbin.com/zolotimofeqe/1 Commented Aug 25, 2014 at 4:42
  • may be clearing cache solves your problem. Commented Aug 25, 2014 at 4:49
  • Kheema, I looked at the source code of your link. I'm not familiar with JS Bin, but as soon as I removed the line "<script src="static.jsbin.com/js/render/edit.js?3.18.32"></script>", I was able to scroll again.
    – S. Valmont
    Commented Aug 25, 2014 at 4:50

1 Answer 1

1

To fix this you need to define a height for your HTML and your BODY. For some reason you also have to remove the margin and padding of the HTML and BODY.

body, html {
overflow: hidden;
margin: 0;
padding: 0;
height: 100%;
}

Without a height defined for these elements your div isn't overflowing anything is how I understand chrome to be interpreting it.

That should take care of the slight scrolling your experiencing. Worked great when I did it.

Best of luck

3
  • One of the first things I tried. In the case of my code sample above, adding this CSS reduced the amount of scrolling allowed, but I'm still able to "wiggle" the DIV up and down. Also, my main point was that this seems to be unexplained behavior that's specific to the current PC version of Chrome. I do not need to do anything beyond my original code sample in other browsers to prevent scrolling. The DIV already knew what it shouldn't overflow.
    – S. Valmont
    Commented Aug 25, 2014 at 5:48
  • I'm sorry I updated my post. I forgot to add you need to remove margins and padding apparently to really get rid of scrolling. I also added to my answer about how I believe it is working. Unfortunately it may just be an unintended bug. So in answer to your main point, it appears you are absolutely right; chrome does seem to act this way for no apparent reason. Weird. Either way, I hope this work around can be useful to you anyways. Good luck!
    – Josh R.
    Commented Aug 25, 2014 at 6:09
  • I used this with overflow-x: hidden; and it left a weird lengthy whitespace after the footer of the website. This happens only in Chrome, not in Firefox. I'd suggest finding some other way to hide overflow, perhaps directly on the overflowing elements (not html or body).
    – ADTC
    Commented Feb 24, 2021 at 0:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.