Force <div> to fill all available vertical spaces
I've seen a bunch of ways to do this online, but everything I've tried either broke other CSS on the page or didn't work all together.
From this page http://www.psyklopz.com/workbench/ I want the #container element to grow in height so that the footer touches the bottom of the screen.
How do you do it?
source to share
I ended up using position: fixed;
and installing bottom: 0; top: 0; left: 0;
. Then I used a piece of jQuery magic .animate()
to pull it out. Here's a working code and an all-in-one demo!
http://www.psyklopz.com/workbench/jquery-based-dock-toolbar/
source to share
You can also do:
Html
<body>
<div id="container"></div>
<div id="footer"></div>
</body>
Styles
html,body {height: 100%;}
body{ position: relative;}
#footer { position: absolute; bottom: 0;}
The container container won't stretch all the way down, but with clever use of BG colors, you can make it look like it does.
source to share
I know this is an old post, but I ran into a similar problem today.
I wanted to have a container (with a map) to fill the viewport, but there had to be a 32px container above it. The map made it necessary to really expand the container to its maximum size and not overlap with anything else. I ended up using a flexible and elegant solution without javascript:
<div class="tab"><div class="tabContent" /></div
<div class="container" />
And the CSS:
.tab {
height: 0;
width: 100%;
}
.tabContent {
height: 32px;
}
.container {
height: 100%;
padding-top: 32px;
box-sizing: border-box;
-moz-box-sizing: border-box;
-o-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
The trick is using the box size: border-box to make the height: 100% include some padding.
I also created a jsfiddle: http://jsfiddle.net/YWLLM/2/ I had to use fixed body height in fiddle because (at least in chrome) at iframe height: 100% didn't work. I also added some borders to visualize that nothing is being clipped (with container overflow: hidden)
source to share