This is the simple code:
<div id="container">
<div id = "information">
</div>
</div>
When I change the "information" to width 1000, and container width 100, the "information" become very long, but I would like to let the information div inside the div...I means, I want the container have a scroll bar, if the information's width is longer than the container. How can I do so? Thank you.
For vertical scrollable bar use the x and y axis. Set the overflow-x:hidden; and overflow-y:auto; that will automatically hide the horizontal scroll bar and present only vertical scrollbar. Here the scroll div will be vertically scrollable.
The secret there is to use box-sizing: border-box , and some padding to make the second div height 100%, but move it's content down 50px. Then wrap the content in a div with overflow: auto to contain the scrollbar. Pay attention to z-indexes to keep all the text selectable - hope this helps, several years later.
The scrollbar can be triggered with any property overflow , overflow-x , or overflow-y and each can be set to any of visible , hidden , scroll , auto , or inherit .
For horizontal scrollable bar use the x and y-axis. Set the overflow-y: hidden; and overflow-x: auto; that will automatically hide the vertical scroll bar and present only the horizontal scrollbar. The white-space: nowrap; property is used to wrap text in a single line.
#container {
overflow: auto;
}
This should do the trick:
#container
{
overflow: auto;
}
Set overflow: auto
in the stylesheet.
That said, it is almost always better to make use of the available space and not introduce small regions with their own scrollbars (which are harder to deal with with AT, and require scrolling more frequently to read)
Or use overflow-x
and overflow-y
to limit the scrolling to just vertical or horizontal.
#container { overflow-x: auto; } /* Horizontal scrolling only */
or
#container { overflow-y: auto; } /* Vertical scrolling only */
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With