Need a Fluid-Height Sidebar - Same Height as Container
I need a sidebar to stretch down as much as its container div does. I haven't set a height for the container because I want it to be as tall as whatever content goes in it. I wanted the sidebar to be height:100% but since I haven't set the container height, it's still on 'auto', so that doesn't work.
How do you get a sidebar height to be 100% of its container, while keeping the container fluid?
(Sorry I can't post markup and css to explain what I mean yet, I will soon if needed... but I'll have to make a whole new example page for that + I'm a bit busy right now. )
A late solution not posted yet
Hi Fretman,
I have a solution here. Works in all modern browsers, including IE9 and IE8. IE 7 and 6 do not take it, though.
HTML:
Code:
<div id="wrapper">
<div id="main_col" class="same_height_col">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque bibendum gravida nibh,
nec adipiscing ante pretium nec. Pellentesque suscipit magna nibh. In pulvinar dolor et massa
ultricies adipiscing. Proin aliquam odio in ligula pellentesque quis semper tortor fermentum.
Duis libero metus, tempus porta rutrum non, pulvinar in libero. Praesent nec eleifend augue.
Aenean laoreet malesuada interdum. Morbi quis metus id velit suscipit sagittis vitae vel libero.
Aliquam erat volutpat. Maecenas et turpis sed justo fermentum vulputate a et dui. Aliquam erat
volutpat. Pellentesque elementum iaculis suscipit. Duis pellentesque quam quis urna dapibus
sodales. Mauris posuere, mi non faucibus ullamcorper, nulla orci luctus ipsum, id sollicitudin
sapien est sit amet mauris.</p>
</div>
<div id="sidebar_col" class="same_height_col">
<p>Maecenas nibh eros, feugiat ac varius vel, sodales eu augue. Mauris quis orci ac tortor feugiat
fringilla. Donec ac justo in mauris hendrerit pellentesque in at orci.</p>
</div>
</div>
CSS:
Code:
#wrapper {
width: 720px; /* this is just arbitrary, to avoid making the whole thing fill up the entire screen */
overflow: visible;
display: table;
table-layout: fixed;
border: 1px solid #666; /* to make the height of the container div visible */
}
#main_col {
width: 65%;
background-color: #8CE; /* this makes the column height visible */
}
#sidebar_col {
width: 30%;
background-color: #FDF; /* this makes the column height visible */
}
#wrapper .same_height_col {
display: table-cell;
overflow: hidden;
vertical-align: top;
}
Cheers