Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you add a scroll bar to a div?

Tags:

css

scroll

popup

I have a popup that displays some results, and I want a scroll bar to be display since the results are being cutt off (and I don't want the popup to be too long).

like image 427
Blankman Avatar asked May 14 '10 18:05

Blankman


People also ask

How do you add a scrollbar to a div in HTML?

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.

Can a div be scrollable?

The content in the <div> is scrollable, but neither the <div> itself nor any of its content is tabbable. As a result, keyboard users can't operate the scrollbar to see all of the content.

How do I add a horizontal scroll bar to a div?

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. Here the scroll div will be horizontally scrollable.


3 Answers

You need to add style="overflow-y:scroll;" to the div tag. (This will force a scrollbar on the vertical).

If you only want a scrollbar when needed, just do overflow-y:auto;

like image 170
Mitch Dempsey Avatar answered Oct 20 '22 01:10

Mitch Dempsey


Css class to have a nice Div with scroll

.DivToScroll{   
    background-color: #F5F5F5;
    border: 1px solid #DDDDDD;
    border-radius: 4px 0 4px 0;
    color: #3B3C3E;
    font-size: 12px;
    font-weight: bold;
    left: -1px;
    padding: 10px 7px 5px;
}

.DivWithScroll{
    height:120px;
    overflow:scroll;
    overflow-x:hidden;
}
like image 35
Ricardo Lima Avatar answered Oct 20 '22 01:10

Ricardo Lima


If you want to add a scroll bar using jquery the following will work. If your div had a id of 'mydiv' you could us the following jquery id selector with css property:

jQuery('#mydiv').css("overflow-y", "scroll");
like image 15
ScottyG Avatar answered Oct 19 '22 23:10

ScottyG