javascript – Disallow horizontal scroll on mobile devices

Question:

I need to disallow horizontal scroll on mobile, especially on iOS, as overflow works correctly on Android.

Now I have the following css content:

html, body{
    overflow-x: hidden;
}

The head says:

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>

It is necessary to prohibit it specifically for the body, and not for a separate element.

Answer:

Try this:

html, body {
    max-width: 100%;
    overflow-x: hidden;
}
Scroll to Top