rulururu

post How to stretch sidebar(div) vertically (whole height of site) ?

June 9th, 2010

Filed under: CSS,Tip — Alex Bylim @ 5:22 pm

Hey dudes, I know there are a lot of different approaches make two-columns layout, and to make sidebar stretch vertically. But always there is one problem: side bar should fill vertical side area 1) when content longer then sidebar 2) when content shorter then sidebar. So here is how to solve this with CSS:

/* this will allow sidebar stretch vertically in right way */
html, body {
	min-height:100%;
	position: absolute; 
        width:100%;
}
 
/* stretching our sidebar */
#sidebar{
 width: 300px;
 height: auto;
 min-height:100%;
 position:absolute;
 background-color: #555;
}

To make content block is not to hard and you need is to set margin-left the same width as sidebar width

  • http://pulse.yahoo.com/_RUUNZQWU3HKPVC22URAAG36BDY Happy Cheese

    Hi,
    I’ve heard of height: 100%, but for some reason it doesn’t seem to work on my site. Is it because the sidebar is set to float: right?

  • http://default-value.com Alex Bylim

    Hi! If you’ll give me link to page with problem I’ll help to solve it

ruldrurd
Powered by WordPress, Web Design by Laurentiu Piron
Entries (RSS) and Comments (RSS)