Home >Web Front-end >CSS Tutorial >How Can I Prevent Scrolling and Hide Content Beyond the Viewport on iOS Devices?

How Can I Prevent Scrolling and Hide Content Beyond the Viewport on iOS Devices?

Linda Hamilton
Linda HamiltonOriginal
2024-12-14 08:45:15931browse

How Can I Prevent Scrolling and Hide Content Beyond the Viewport on iOS Devices?

Hide Content Beyond the Fold on iPhone/iPad

Disabling scrolling on mobile Safari for long pages can be a challenge. Applying overflow: hidden to the element alone may not suffice. Here's a solution that works:

Solution:

Apply overflow: hidden; to both the html and body elements:

html,
body {
    overflow: hidden;
}

For iOS 9, you might need this instead:

html,
body {
    overflow: hidden;
    position: relative;
    height: 100%;
}

This will prevent the page from scrolling and hide any content that extends beyond the viewport. Note that this solution may not be suitable for all websites, as it can break some functionalities, such as sliders or dropdowns, that rely on scrolling.

The above is the detailed content of How Can I Prevent Scrolling and Hide Content Beyond the Viewport on iOS Devices?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn