How to Control Horizontal Scrollbars in CSS 'div' Elements?

Susan Sarandon
Release: 2024-11-11 15:38:03
Original
339 people have browsed it

How to Control Horizontal Scrollbars in CSS 'div' Elements?

Controlling Horizontal Scrollbars in a CSS 'div' Element

When working with 'div' containers in CSS, you may encounter a situation where you desire horizontal scrollbars only. This article addresses how to achieve this behavior.

In the provided code snippet, you have configured the 'overflow' property to 'auto,' which allows both horizontal and vertical scrolling when the content exceeds the specified width or height. To restrict scrolling to the horizontal plane, modify the 'overflow-y' property as follows:

div#tbl-container {
    overflow: hidden;
    overflow-y: auto;
    scrollbar-base-color: #ffeaff;
}
Copy after login

By setting 'overflow-y' to 'auto,' you allow automatic vertical scrolling if the content height exceeds the 'div' height, while 'overflow' being set to 'hidden' prevents horizontal scrolling unless the content width exceeds the specified 'div' width.

In Internet Explorer (IE) versions 6-7, an additional CSS3 extension is required for suppressing the vertical scrollbar:

div#tbl-container {
    overflow: auto;
    overflow-y: hidden;
    scrollbar-base-color: #ffeaff;
    -ms-overflow-y: hidden;
}
Copy after login

This '-ms' prefix is employed to accommodate IE8 due to Microsoft's designation of pre-candidate recommendation standard properties under its own namespace.

It's noteworthy that IE8 may have addressed this bug, eliminating the need for the '-ms' prefix. Nevertheless, the CSS modifications mentioned above should provide the desired outcome in controlling scrollbars for 'div' elements.

The above is the detailed content of How to Control Horizontal Scrollbars in CSS 'div' Elements?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template