tags:

views:

120

answers:

1

I have a setup that requires a header div and a footer div to stay rooted at the top and bottom of the page respectively, while the content div in the middle fills up the area in between. The content div is set to overflow:auto; so a scroll bar appears when content volume is large enough. Something like this:

+----------------------------------------------+                 <-
|header div with fixed height of 90px          |                   |
+----------------------------------------------+                   |
|content div with variable height             ||                   |
|                                             || <-scroll bar      |
|                                             ||   (if required)   |
|                                             ||                   |- total window height
|                                             ||                   |
+----------------------------------------------+                   |
|footer div with fixed height of 60px          |                   |
+----------------------------------------------+                 <-

I want the content div alone to change its height in a way that the combination of the three fill the whole window. Is it possible to do it with CSS alone? Thanks.

(Currently the header and footer divs have position:fixed; and content has height:100%; but it looks hideous.)

+1  A: 

You can do it using position:fixed, although IE support for this is not great. Here's something you might be able to use:

<html>
    <head>
     <style>
#header { position: fixed; top: 0px; left: 0px; width: 100%; height: 90px; }
#footer { position: fixed; bottom: 0px; left: 0px; width: 100%; height: 60px; }
#content { position: fixed; width: 100%; height: auto; top: 90px; bottom: 60px; overflow: auto }
     </style>
    </head>
    <body>
     <div id="header">Header</div>
     <div id="content">
      <p>Content</p>
      <p>Content</p>
      ...etc...
      <p>Content</p>
     </div>
     <div id="footer">Footer</div>
    </body>
</html>

See here for more information, including another example.

Mark Byers
Hey, that seems to work just perfectly! Thanks! Using position: fixed; for all is fairly neat, though it's not really working with IE at the moment :)
mathon12
I think it works in IE8 now
WilliamLou