Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the div become a container with scroll bar?

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.

like image 927
Tattat Avatar asked Dec 02 '10 14:12

Tattat


People also ask

How do I make a div with scrollbar?

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.

How do you make a scroll into a container?

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.

Can div have scrollbar?

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 .

How do I create a horizontal scrolling container?

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.


4 Answers

#container {
    overflow: auto;
}
like image 110
Tatu Ulmanen Avatar answered Sep 25 '22 17:09

Tatu Ulmanen


This should do the trick:

#container
{
    overflow: auto;
}
like image 25
Robert Koritnik Avatar answered Sep 25 '22 17:09

Robert Koritnik


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)

like image 27
Quentin Avatar answered Sep 29 '22 17:09

Quentin


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 */
like image 22
elMarquis Avatar answered Sep 26 '22 17:09

elMarquis