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:
(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?
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.
It just means 100% of the div or class or tag it is enclosed within.
Syntax: height: length|percentage|auto|initial|inherit; Property Values: height: auto; It is used to set height property to its default value.
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.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With