开发者

How can I pin a div in my sidebar column to the bottom?

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/


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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜