tags:

views:

11150

answers:

6

I have a page structure similar to this:

<body>
<div id="parent">
    <div id="childRightCol">
    <div>
    <div id="childLeftCol">
    <div>
</div>
</body>

I would like for the parent div to expand in height when the inner div height expands.

Edit: One caveat is that if/when the width of the child content expands past the width of the browser window, my current CSS puts a horizontal scroll on the parent div. I would like the scrollbar to be at the page level. (Currently my parent div is set to overflow: auto;)

Can you please help me with the CSS for this?

A: 

add a clear:both. assuming that your columns are floating. Depending on how your height is specified parent you may need an overflow:auto;

<body>
<div id="parent">
    <div id="childRightCol">
    <div>
    <div id="childLeftCol">
    <div>
    <div id="clear" style="clear:both;"></div>
</div>
</body>
bendewey
Doing this gives me a horizontal scrollbar on the parent div when the content is wider than the browser window. I would like the horizontal scroll to be on the whole page.
Steve Horn
Why do you need the overflow:auto;? In my test the clear:both; sufficed.
Paolo Bergantino
This also assuming that the parent doesn't have a height specified.
bendewey
This approach works fine in Firefox, but doesn't work in IE 6. Any workarounds?
Steve Horn
+1  A: 

Are you looking for a 2 column CSS layout?

If so, have a look at the instructions, it's pretty straightforward for starting.

lpfavreau
A: 

Using something like self-clearing divs is perfect for a situation like this.

http://www.positioniseverything.net/easyclearing.html. Then you'll just use a class on the parent... like:

<div id="parent" class="clearfix">
Tim K.
A: 

I am having problem with divs expanding with comments anyone know how to do it correctly, i've looked and looked and have yet to find a definite answer. Thanks

austin web design
A: 

Does this do what you want?

.childRightCol, .childLeftCol
{
    display: inline-block;
    width: 50%;
    margin: 0;
    padding: 0;
    vertical-align: top;
}
Eric
A: 

For those who can not figure out this in instructions from this answer there:

Try to set padding value more then 0, if child divs have margin-top or margin-bottom you can replace it with padding

For example if you have

#childRightCol
{
    margin-top: 30px;
}
#childLeftCol
{
    margin-bottom: 20px;
}

it'll be better to replace it with:

#parent
{
    padding: 30px 0px 20px 0px;
}
McAngel