1

I have a issue with the left sidebar.

I would like to make the left sidebar 100% height of the browser always no matter what content is there in right hand panel.

<div class="container">
    <div class="leftwrapper">Some text</div>
    <div class="rightwrapper">Some text for right</div>
</div>

Fiddle -- http://jsfiddle.net/squidraj/32uppbhy/

Raj
  • 1,377
  • 6
  • 23
  • 48

3 Answers3

4

Add the following rule to the top of your CSS:

html, body, .container, .leftwrapper {height:100%;}
Luke Baughan
  • 4,658
  • 3
  • 31
  • 54
4

Percentage heights are relative, you want the containing element .container to stretch the full height of the viewport, so it needs a height of 100%, but 100% of what? So you also need to set it on your html and body elements. Then simply give your absolutely positioned sidebar bottom:0; to stretch it the full height.

Simply change your CSS thus:

html, body { /* ensure the available document space is the full height of the viewport */
    height:100%;
    padding:0;
    margin:0;
}
.container {
    overflow: hidden;
    position: relative;
    height:100%; /* <-- make the containing element full height */
}
.leftwrapper {
    background-color: #0b7582;
    bottom: 0;
    float: left;
    position: absolute;
    text-align: center;
    top: 0;
    width: 8%;
    bottom:0; /* <-- anchor the element to both the top and the bottom of the viewport */
}
.rightwrapper {
    float: left;
    margin-left: 8%;
    width: 92%;
}
SW4
  • 69,876
  • 20
  • 132
  • 137
3

Few elements derive their height from body and html tags as their parent. What you can do is simply create a new css rule for body and html tag with a height property of 100% and then another rule for your sidebar height to be 100%. Hope it works :)

CSS rules:

html,body{height:100%;}
.sidebar{height:100%;}
ahjashish
  • 573
  • 1
  • 3
  • 13