views:

52

answers:

4

Hi,

I have a div which contains 3 columns (each as a div). The problem is that the height of the parent div is not extending with the height of the columns.

Here are the styles in question:

#content{
background: #fff;
clear: both;
color: #333;
padding: 10px 20px 40px 20px;
overflow: auto;
}

#leftcol { 
position:absolute;
float:left;
top:285px;
z-index:100;
background-color:#EEEEEE;
padding:5px;
-moz-border-radius: 10px;
border-radius: 10px;
}

#rightcol {
position: absolute;
right:208px;
top:285px;
width:177px;
background-color:#EEEEEE;
padding:5px;
-moz-border-radius: 10px;
border-radius: 10px;
}

#centercol {
margin-left: 288px;
margin-right:200px;
background-color:#EEEEEE;
padding:5px;
-moz-border-radius: 10px;
border-radius: 10px;
}

I think it's the absolute positioning in the left and right columns that is messing things up. Every other page that doesn not use the column styles works fine. The height of the parent div extends with what is inside it.

Can someone help me out please?

Jonesy

+1  A: 

Your parent column will not extend to fit the content of the child columns since 2 of them are position: absolute;

If everything were position: relative or all position: absolute it would work.

Mark
+1  A: 

Absolutely positioned elements are taken out of the document flow, so the container div won't 'see' them. Try floating the 3 divs left, and adding overflow:auto; to the container div. The latter (not a blank 'clearing' div) is the current best practice.

Dave Everitt
hi thanks for your reply! I changed all 3 columns to float left and added margin to position them. Everything is in the right place horizontally but vertically the center column is just under the left. is there a fix for that?
iamjonesy
If all 3 columns are now in the right place, do you mean that the center column is slightly shorter than the left? Can you put it up somewhere?
Dave Everitt
hi here's the development site http://booyahachieved.com - its the 3 columns on the homepage
iamjonesy
never mind it was my margins that were messing me up. the center colum had the margins of when it was absolute. all fixed now thanks
iamjonesy
Glad you got it sorted :-)
Dave Everitt
A: 

instead of clear:both, the new a best way to do it is with

overflow:auto

on the parent

before it was suggested to use a div like this

<div class="clear"></div>

at the end of the parent but the best approach is with overflow

Juan Diego
the parent is using overflow:auto, but thanks i didnt know that it had replaced clear:both!
iamjonesy
+1  A: 

Unless there a very pertinent reason you are absolutely positioning the #leftcol and #rightcol, you should be floating them so they are contained within the document flow as Dave Everitt said.

Any particular reason for the absolute position? What seems like a simple layout could easily be accomplished with floats/margins.

dmackerman
hi thanks for the reply, i've floated everything left, positioned everything relative but now everything is in the right place horizontally but vertically the center column is just under the left :(
iamjonesy