Masiar
Masiar

Reputation: 21352

How to make div fixed in height but grows if content is bigger than height?

Let's say I have a div to which I set height: 500px; in CSS, thus it's fixed in height.

The content of my page is generated automatically in JavaScript, thus sometimes it's bigger than 500px and it overflows the div border.

My question is: is it possible to have a fixed size (for example 500px) but when the div's content is greater than 500px, have the div growing bigger to contain that?

Thanks

Upvotes: 12

Views: 18531

Answers (3)

Jeremy McGee
Jeremy McGee

Reputation: 25210

Try

min-height: 500px;
height:auto;

to set a minimum height.

For reference: http://www.w3schools.com/cssref/pr_dim_min-height.asp

Upvotes: 24

omnath
omnath

Reputation: 509

try this


min-height:500px;
overflow:auto;
margin:0 auto;

Upvotes: 2

Sonal Khunt
Sonal Khunt

Reputation: 1894

Yes

min-height:300px;
height:auto;

Upvotes: 6

Related Questions