Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to set vertical scrollbar for a div?

Tags:

html

css

I put a empty content div into a td tag in a table. It shows as there is only one line in div. If I set the height of the div, when I input more content than it's height, it still keep the same size as it was. How to add a vertical scrollbar when content need to consume more space in the div? Thanks.

like image 774
Steven Zack Avatar asked Jul 14 '11 19:07

Steven Zack


3 Answers

Automatically show scroll bars when content is greater than height and width like this:

<div style="overflow:auto;"></div>

OR

Show scroll bars at all times like this:

<div style="overflow:scroll;"></div>

Below is some reference for CSS overflow properties:

overflow

overflow-x

overflow-y

like image 87
John Hartsock Avatar answered Sep 21 '22 20:09

John Hartsock


Use overflow, or overflow-y: auto | hidden | scroll | visible

<div style="max-height:100px; overflow-y:auto"> ... </div>

or

<div style="max-height:100px; overflow-y:scroll"> ... </div>

NOTE: overflow supported since CSS2, but overflow-y - CSS3, Opera 9.6, Safari 3.1

like image 38
Optillect Team Avatar answered Sep 22 '22 20:09

Optillect Team


If you want vertical scrollbar then

<div style="overflow-y:auto;overflow-x:hidden"></div>
like image 45
Chintan Avatar answered Sep 21 '22 20:09

Chintan