Search code examples
htmlcss-floatsidebarcss

extend floated menu, so height is matching the content div


I have a content div and a sidebar, the content div's height will adjust depending on the content being loaded, but I want the sidebar div to be extended all the way down, depending on the max size of the content, the sidebar should be the same size.

Fiddle, Fiddle, Fiddle! - JS Fiddle

View the above fiddle, I want the sidebar extended all the way down, depending on the height of the content div.

For non fiddlers:
CSS

#content
{
border:1px solid black;
float: left;
width: 80%;
}

#sidebar
{
width: 19%;
border:1px solid red;
float: left; 
background-color: #ddd;
}

p{text-align: right}

HTML

<div id="container" style="background-color: #f2f2f2">
<div id="content">Here is the content, the height of this div will vary depending on the content.
    <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
    <p>I dont want this big empty box. --> <br/>I want the sidebar extended down here--></p>
</div>
<div id="sidebar">I want this sidebar to extend ALL the way down, to match the #content divs height (whatever it is, dynamic)</div>
<div style="clear:both"></div>


Solution

  • You will have to use javascript for that. with Jquery it will be somehing like following.

        $('#sidebar').height($('#content').height());
    

    fiddle http://jsfiddle.net/YMFGU/9/