First off, similar but never answered questions:
vertically-scrolling-percentage-based-heights-vertical-margins-codepen-exampl
scroll-bar-on-div-with-overflowauto-and-percentage-height
I have an issue with scrolling a center part of the web page while its height needs to be auto.
Here is a fiddle
The header needs to be on top at all times, meaning I don't want the body to become larger than 100%.
However the div #messages can become larger, and that div needs to scroll on its own.
The #messages has a margin-bottom to leave room for the fixed bottom div.
I tried making the div #messages
with box-sizing: border-box;
and making it height:100%
and padding to keep it in place but this was a really nasty looking solution and the scroll bar was the full page height instead of only the inner part.
Any help would be greatly appreciated.
You could try the following.
You HTML is:
Apply the following CSS:
See demo at: http://jsfiddle.net/audetwebdesign/5Y8gq/
First, set the height of 100% to the
html
andbody
tags, which allows you to reference the view port height.You want the
#header
to be fixed towards the top of the page usingposition: fixed
, similarly for your footer#input
.The key is to use absolute positioning on
#content
to stretch it between the bottom edge of the header and the top edge of the footer, and then applyoverflow-y: scroll
to allow it to scroll the content (list of messages).Comment
The source code for the
#input
block may be placed outside of the#content
block.You want something like This
Or maybe - his big brother..
Pure CSS solution, without fixing any height.
HTML:
CSS: