1

I have a problem combining div boxes and the overflow: auto property for adding scrollbars if needed.

The problem is that I don't want the whole page to be scrollable, but just the content div, thus I added overflow: hidden to the body and overflow: auto to the content.

body
{
    padding: 0;
    margin: 0; 
    background-color: navy; 
    overflow: hidden; /** no scrollbar on whole page **/
    height: 100%;
}

#content
{
    background-color: green;
    overflow: auto; 
    height: 100%;
}

Nevertheless, I'm not able to see the end of the page, as the div increases its size beyond the viewable part of the website.

Please suggest how to solve this problem and only keep the content div scrollable. I uploaded an example of my problem here: jsfiddle.net/3n7ay/

I can only get this to work with a fixed header height, is there no solution for dynamic header size? It's hard for me to believe...

Thanks & Regards

0

3 Answers 3

1

I think you looking for overflow-y: scroll; instead?

See fiddle: http://jsfiddle.net/3n7ay/5/

Sign up to request clarification or add additional context in comments.

2 Comments

This will not solve the problem unfortunately. If I add overflow-y to the body, it will display the scrollbar for the whole body, which is unwanted. I only need the scrollbar on the content-div.
So put overflow-y: scroll on the content-div then. As I have in my fiddle.
0

If you set height: 100% to the content element and you have also an header in your viewport this will make the former not entirely visible inside the viewport itself.

So the height must be defined as 100% - <header height>, either via javascript (if you need to support older browser) or via CSS3 calc() function, e.g.

#content {   
   height: -webkit-calc(100% - <height of header>px);
   height: -moz-calc(100% - <height of header>px);
   height: calc(100% - <height of header>px);
}

2 Comments

This sounds quite promising. What is the solution if I have a header that's dynamically sized depending on the size of content inside? This is exactly the case here.
@user3410218 If calc is promising, what about flex box?
0

Try flex box, if you don't concern about Ie8 and Ie9. You can see the compatibility situation in caniuse.com: flexbox

Make container a flex box:

#container {
    background-color: yellow;
    height: 100%;
    display: -ms-flexbox;
    display: -webkit-flex;
    display: flex;
    -ms-flex-direction: column;
    -webkit-flex-direction: column;
    flex-direction: column;
}

Flex the content:

#content {
    background-color: green;
    overflow: auto;
    height: 100%;
    -ms-flex: 1;
    -webkit-flex: 1;
    flex: 1;
}

See fiddle: http://jsfiddle.net/r4JUk/4/

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.