When using overflow: auto
, both vertical and horizontal scrollbars will be displayed if necessary.
The reason for your confusion lies in the markup and associated styles you are using. If the content does not require both scroll bars, only the vertical one will be displayed.
This is because by default, content wraps unless specified otherwise. Elements like table
try to shrink-fit unless explicitly told not to. If a table's content exceeds the width, a horizontal scrollbar will appear. Content that doesn't wrap will also trigger the appearance of the horizontal scrollbar.
Demo: http://jsfiddle.net/abhitalks/4wWNU/4/
CSS:
div {
border: 1px solid gray;
height: 100px; width: 200px;
overflow: auto;
}
div#d2, div#d3 {
white-space: nowrap;
}
div#d4 > table {
width: 150%;
}
In the provided fiddle, observe each div
:
In the first one, simple text content wraps vertically, showing only the vertical scrollbar.
In the second one, content is forced not to wrap with white-space: nowrap;
, displaying only the horizontal scrollbar.
In the third one, multiple p
tags prevent wrapping, so both scrollbars appear when overflowing.
In the fourth one, an oversized table triggers display of both scrollbars. Removing the table's width setting causes it to fit within the container, showing only the vertical scrollbar.