Randomblue Randomblue - 1 year ago 95
HTML Question

Prevent "overscrolling" of web page

In Chrome for Mac, one can "overscroll" a page (for lack of a better word), as shown in the screenshot below, to see "what's behind", similar to the iPad or iPhone.

I've noticed that some pages have it disabled, like gmail and the "new tab" page.

How can I disable "overscrolling"? Are there other ways in which I can control "overscrolling"?

enter image description here

Answer Source

One way you can prevent this, is using the following CSS:

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;

body > div {
    height: 100%;
    overflow: scroll;
    -webkit-overflow-scrolling: touch;

This way the body has never any overflow and won't "bounce" when scrolling at the top and bottom of the page. The container will perfectly scroll its content within. This works in Safari and in Chrome.


Why the extra <div>-element as a wrapper could be useful:
Florian Feldhaus' solution uses slightly less code and works fine too. However, it can have a little quirk, when it comes to content that exceeds the viewport width. In this case the scrollbar at the bottom of the window is moved out of the viewport half way and is hard to recognize/reach. This can be avoided using body { margin: 0; } if suitable. In situation where you can't add this CSS the wrapper element is useful as the scrollbar is always fully visible.

Find a screenshot below: enter image description here