Steven Zack
Steven Zack

Reputation: 5104

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

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.

Upvotes: 16

Views: 84853

Answers (5)

Chintan
Chintan

Reputation: 545

If you want vertical scrollbar then

<div style="overflow-y:auto;overflow-x:hidden"></div>

Upvotes: 1

John Hartsock
John Hartsock

Reputation: 86872

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

Upvotes: 22

Optillect Team
Optillect Team

Reputation: 1747

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

Upvotes: 12

calumbrodie
calumbrodie

Reputation: 4792

do this in css

div {overflow: scroll}

edit: What's with all the inline styles guys :-(

Upvotes: 0

JAiro
JAiro

Reputation: 5999

only vertical scroll

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

Upvotes: 0

Related Questions