Home >Web Front-end >CSS Tutorial >How to Show Only Horizontal Scroll Bars in a CSS Div Element?
How to Show Horizontal Scroll Bars Only in CSS Div Element
Div containers are commonly used for display elements in HTML. To automatically display both horizontal and vertical scroll bars when the content exceeds the defined width and height of the div, the overflow property can be set to auto.
Problem:
When a div container has its style defined with overflow: auto, both horizontal and vertical scroll bars appear automatically, even if the content only overflows horizontally. The goal is to show only horizontal scroll bars while controlling the height of the table programmatically.
Solution:
The key to resolving this issue lies in utilizing the proposed CSS3 extension, which allows independent control of scrollbars. Here's how it can be achieved:
overflow: auto; overflow-y: hidden;
This CSS code hides the vertical scrollbar while allowing the horizontal scrollbar to appear automatically.
IE Compatibility:
IE6-7, along with other browsers, support the CSS3 extension for scrollbar control. However, IE8 introduces an additional requirement:
-ms-overflow-y: hidden;
This line ensures backward compatibility in IE8 Standards Mode, addressing a potential Microsoft implementation change.
Additional Notes:
The above is the detailed content of How to Show Only Horizontal Scroll Bars in a CSS Div Element?. For more information, please follow other related articles on the PHP Chinese website!