2

More specifically, I have a right sidebar that spans the right side of the browser window. That part hasn't presented any problems. However, I want it to contain a div that is also 100% of the browser height, but with a top and bottom margin. The contents inside this div will scroll if the content won't fit within the browser window height. I can't get it to work. Here is my code:

HTML:

<div class="outerWrap">
    <div class="innerWrap">
        // stuff
    </div>
</div>

CSS:

.outerWrap { // this works
    position: fixed;
    right: 0;
    top: 0;
    height: 100%;
    width: 277px;
}

.innerWrap { // this doesn't work
    width: 277px;
    margin: 152px 0px 10px 0px;
    overflow-y: scroll;
    overflow-x: hidden;
    height: 100%;
}

How can I get this to work so I have a top and bottom margin on the inner div?

2
  • 2
    Maybe you should make a diagram of what you are after? A div with 100% height, but with top and bottom margins doesn't make much sense..
    – Kyle
    Jul 10, 2012 at 6:31
  • I want the height of the outer div to be 100% of the whatever the users browser window size is. I have achieve this with no problems. I also want a div inside this outer div that has a top and bottom margin, but otherwise fills all of the remaining height, whatever that may be. Jul 10, 2012 at 6:35

1 Answer 1

0

Use -

Fiddle - http://jsfiddle.net/EKm7p/

html, body{height: 100%;}
.outerWrap {    
    height: 100%;
    width: 277px;
    border: 1px solid #f00;
}
.innerWrap {
    margin: 152px 0px 10px 0px;
    overflow-y: scroll;
    width: 277px;   
    display: block;
    position:absolute;
    height:auto;
    top:0;
    left:0;
    bottom:0;
    background-color: green;
}
1
  • 1
    Yes! Absolute positioning was the key. Thanks so much! Jul 10, 2012 at 6:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.