Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set the overflow:auto with height 100%

Tags:

css

In my page, I have an element which has a height of 100% based on its parent; however, I want this element to auto scroll vertically when necessary. This is my example.

I can not make it.

I have added the following css:

height:100%;
max-height:100%;

In fact, what I want is to make sure that the .content is always inside the .container. Like this:

pic.

(BTW, in the above image, I use the max-height:400px which should be avoided since the maximum height of it should be based on the height of .container)

Any ideas?

like image 920
hguser Avatar asked Jan 09 '13 05:01

hguser


People also ask

How do I make my height 100% in HTML?

Adding min-height:100% gives you the default height you want body to have and then allows the page dimensions to fill the viewport without content breaking out of the body. This works only because html has derived its 100% height based on the viewport.

What does CSS height 100% do?

It just means 100% of the div or class or tag it is enclosed within.

How do I set auto height in CSS?

Syntax: height: length|percentage|auto|initial|inherit; Property Values: height: auto; It is used to set height property to its default value.

What is the correct function of overflow auto?

overflow: auto The auto value is similar to scroll , but it adds scrollbars only when necessary: You can use the overflow property when you want to have better control of the layout. The overflow property specifies what happens if content overflows an element's box.


1 Answers

This is close to the solution you are looking for, though you may need to adjust the padding and such for a more aesthetically pleasing look: http://jsfiddle.net/GJ5yM/

New CSS:

    .content{
        height:100%;
        position: absolute;
    }
    .windowcontent{
        background-color: white;
        padding: 10px;
        max-height:100%;
        position:relative;
        overflow-y:auto;
    }
like image 156
Wes Cossick Avatar answered Oct 05 '22 09:10

Wes Cossick