I can get a 100% height div, like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>T5</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css"
href="http://yui.yahooapis.com/3.0.0/build/cssreset/reset-min.css">
</link>
<style type="text/css">
* { padding: 0; margin: 0; }
html, body { height: 100%; }
body {
font-family: "lucida sans", verdana, arial, helvetica, sans-serif;
font-size: 75%;
}
h1 { font-weight: bold; font-size: 1.4em; padding: 10px 10px 0;}
p { padding: 0 10px 1em; }
#container {
min-height: 100%;
background-color: #DDD;
border-left: 2px solid #666;
border-right: 2px solid #666;
width: 280px;
margin: 0 auto;
}
* html #container { height: 100%; }
</style>
</head>
<body>
<div id="container">
<h1>100% Height Div</h1>
<p>Lorem ipsum ...</p>
</div>
</body>
</html>
It looks like this:
When I say "100% height" - I mean it stays full height regardless of how much content is in the div, and regardless of how the window gets resized.
But is it possible to get a div with a height of "almost 100%" height? If I want margins at the top and bottom, can I do that?
I want it to look like this:
I can do this with Javascript+CSS. Can I do it with just CSS?
Answer:
Yes, it's possible with absolute positioning.
#container {
width: 380px;
background-color: #DDD;
border: 2px solid #666;
position: absolute;
top: 20px; /* margin from top */
bottom: 20px; /* margin from bottom */
left: 50%; /* start left side in middle of window */
margin-left: -190px; /* then, reverse indent */
overflow: auto; /* scrollbar as necessary */
}
Result:
Thanks to keithjgrant for the answer. See all the code at http://jsbin.com/otobi .