Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Div not expanding even with content inside

Tags:

html

css

I have a stack of divs inside of each other, all of which have an ID which specifies CSS only.

But for some reason the surrounding DIV tag only expands to it's anointed height value, and not it's default auto, meaning that although the content is inside, the backing DIV is only a specific height. I need it to adjust the heigh to the size of whatever is inside of it (As there will be user submitted data being echoed out possibly in paragraphs with 500+ words.)

#albumhold {    width: 920px;    padding: 10px;    height: auto;    border: 1px solid #E1E1E1;    margin-left: auto;    margin-right: auto;    background-color: #E1E1E1;    background-image: url(../global-images/albumback.png);    background-position: top center;    background-repeat: repeat-x;  }    #albumpic {    display: block;    height: 110px;    width: 110px;    float: left;    border: 1px solid #000;  }    #infohold {    width: 800px;    background-color: #CCC;    float: right;    height: 20px;  }    #albumhead {    width: 800px;    height: 20px;    text-indent: 10px;    border: 1px solid #000;    color: #09F;  }    #albuminfo {    margin-top: 5px;    width: 800px;    float: right;    color: #09F;    word-wrap: break-word;  }
<div id="albumhold">    <div id="albumpic">Pic here</div>    <div id="infohold">      <div id="albumhead">Name | Date</div>      <div id="albuminfo">Information</div>    </div>  </div>

Help is greatly appreciated.

like image 530
Aiden Ryan Avatar asked Apr 25 '11 00:04

Aiden Ryan


People also ask

How do I force a div to full width?

What you could do is set your div to be position: absolute so your div is independent of the rest of the layout. Then say width: 100% to have it fill the screen width. Now just use margin-left: 30px (or whatever px you need) and you should be done.

How do I keep the content inside a div?

Just add overflow: auto; to the <ul> . That will make it so that the text doesn't leak outside of the UL. However, depending on what you're doing, it might be easier to just make the <li> display: inline; . It totally depends on what you're doing!


2 Answers

Floated elements don’t take up any vertical space in their containing element.

All of your elements inside #albumhold are floated, apart from #albumhead, which doesn’t look like it’d take up much space.

However, if you add overflow: hidden; to #albumhold (or some other CSS to clear floats inside it), it will expand its height to encompass its floated children.

like image 70
Paul D. Waite Avatar answered Sep 18 '22 01:09

Paul D. Waite


There are two solutions to fix this:

  1. Use clear:both after the last floated tag. This works good.
  2. If you have fixed height for your div or clipping of content is fine, go with: overflow: hidden
like image 22
Mahendra Liya Avatar answered Sep 19 '22 01:09

Mahendra Liya