tags:

views:

17

answers:

1

I have a simple two column layout with a footer at the bottom. When the content in the sidebar is taller than the content in the main column, everything looks great. But when the height of the main column is greater than the sidebar, I need the sidebar to grow to the same height as the main column and for the last <div> in the sidebar to be pinned to the very bottom.

Here's my sample code:

http://jsfiddle.net/mqnML/1/

+1  A: 

The sidebar will only be as high as its content. One way to fix circumvent that is to wrap both columns into another div. Because you float the columns, end with an element that has clear:both (I added that inline at the bottom). That way the wrapper will be as high as the highest div (in this case the left column). The pin-me-to-bottom div can then be positioned at the bottom of the wrapper, instead of inside the right column. Add position:relative; to the wrapper, so you can position:absolute; the pin-me-to-bottom div.

Result: http://jsfiddle.net/7Mrgu/

Alec
Thanks. The only problem w/ this is that when the main column isn't very high, the pin-me-to-bottom div covers up the sidebar elements above it (because its absolutely positioned). Any way to prevent that?
vg1890
OK, I figured out one thing I could do -- I can set `min-height` on the `wrap_columns` div to make sure the other sidebar elements are visible...but this assumes the sidebar doesn't change in size much.
vg1890
You can also add `padding-bottom` to the sidebar with the height of the pinned div, so that the pinned div overlays empty space. But you're right, if the pinned div is variable in height, this get's tricky. I that case you need 1 column on the left, and 2 stacked columns on the right. But I don't think you can both pin a div to the buttom, _and_ force it to push a previous div _up_. At least not without some JavaScript that reads out the height of the pinned div to calculate the necessary bottom padding/margin for the right top div.
Alec