So i have the following structure
<div id="container">
<div id="head"></div>
<div id="body"></div>
<div id="foot"></div>
</div>
I am only using the ids for illustration purposes so this is not even necessarily for a full page.
I want my container to specify a fixed size... or a relative size, does not matter. Lets for argument sake say 300px height. Also overflow: hidden
I want head/foot to expand to fit the content within itself, so height: auto
is sufficient.
I want the body to expand to fit the remaining space in between head and foot. If the content is too big, then scroll (overflow: auto
).
height: 100%
on #body
does not work because then it gains the height of 300px like the parent and pushes part of itself and the footer out of the parent.
Having head and foot position: absolute
does not work because by taking them out of the document flow, some content of #body
is hidden. To fix that we can use padding-top/bottom but we can't set a padding-top: xxpx
/padding-bottom: xxpx
on the #body
because we don't know the necessary height of the head/foot hence why they are height: auto
.
Edit:
I tried converting the container/head/body/foot into a table where the #body
is height: 100%
. This works great except that #body
won't scroll if the content gets too big, instead the entire table expands to show all content. This is not the desired behavior as I need #body
to scroll, not #content
or it's parent.
Any suggestions?