Reputation: 211
I fixed the width to 900px but I want the height to depend on the amount of text and objects in it. Is there a way to do this, this is the CSS I currently have for the div
#mainbox {
padding:0;
margin:0 auto;
width:900px;
border:solid 2px
}
Upvotes: 1
Views: 3569
Reputation: 22732
The code you have does that. Here's a JSFiddle demo. The only thing I changed is I made your ID into a class, since I was putting multiple div
s in there.
If you don't specify a height, and the div
has not been set to position: absolute
, position: fixed
and its content is in normal flow (e.g. not float:left
or float:right
or with a weird position
) then the height should adjust fine with the content.
Upvotes: 0