tags:

views:

181

answers:

1

The layout I want to achieve is pretty simple. I want a 100% height layout with a header, and below the header I will have a side bar for navigation and then the content area beside the navigation bar (2-column with header). I can easily do this if I give the header a specified height but I want the header to just take up as much room as is needed. Does anyone know how to do this? Is it possible without knowing the height of the header?

Thanks for any help.

+1  A: 

This should do it

<style type="text/css" media="screen">
body
{
  margin: 0;
  padding: 0;
  height: 100%; /* this is the key! */
  width: 100%;
}
#container
{
  position: fixed;
  height: 100%;
  width: 100%;
  background: #eaeaea;
}
#header
{
  background: #000000;
}
</style>

<body>
  <div id="header">
    <br />
    <br />
    <br />
    <br />
  </div>
  <div id="container">
    <table width="100%" style="height: 100%;">
      <tr>
         <td style="background: #ff0000; width: 250px;">
             col1
         </td>
         <td style="background: #00ff00;">
             col2
         </td>
      </tr>
    </table>
  </div>
</body>
alejandrobog
Agreed. The reason that the 100% height on the body is key is that without it, the browser has no way to calculate what 100% means for #container and defaults to the height of the browser window, which is not what you want. It's probably worth tacking !important onto the body's height declaration (height: 100% !important;) and/or a helpful comment so that future developers know not to mess with it.
Dan M
Thanks! For anyone else trying to do this as alejandrobog and Dan M mentioned the 100% on the body is key. The thing I over looked though was the position: fixed on the container.
Brian D.