Home >Web Front-end >CSS Tutorial >How to Truly Disable Horizontal Scrolling on a Webpage?
Preventing Horizontal Scrolling on a Webpage
When a webpage displays excessive white space and scrolls horizontally, it can create an undesirable user experience. This article explores how to disable the horizontal scroll feature on a webpage.
One common misconception is that hiding the scrollbar using CSS's "overflow-x:hidden" property is sufficient to prevent horizontal scrolling. However, this only makes the scrollbar invisible and does not disable the scrolling functionality.
To truly disable horizontal scrolling, you can use the following CSS code:
<code class="html">html, body { max-width: 100%; overflow-x: hidden; }</code>
This code sets the maximum width of the網頁 to 100% of the viewport, ensuring that there is no excess space for horizontal scrolling. Additionally, the "overflow-x: hidden" property explicitly prevents the webpage from scrolling horizontally.
By implementing this CSS, you can effectively disable the horizontal scroll feature on your webpage, restricting user interaction to vertical scrolling only, enhancing the overall user experience.
The above is the detailed content of How to Truly Disable Horizontal Scrolling on a Webpage?. For more information, please follow other related articles on the PHP Chinese website!