tags:

views:

77

answers:

1

Judging by earlier questions and their lack of answers, I'm not sure there will be a good answer for this. Fortunately, we only need to support newer browsers.

Looking for a layout to let us have a 3 rows with a fixed-size header and footer, but the center row is fluid with the height of the browser but will also scroll when it's content is too big.

Possible without JavaScript? We tried (simplified example):

<html style="height: 100%">
<body style="height: 100%">
<section style="height: 100%; display: table;">
  <header style="display: table-row; height: 200px;">
    Header
  </header>
  <section style="display: table-row; height: 100%; overflow-y: auto;">
    Content
  </section>
  <footer style="display: table-row; height: 200px;">
  </footer>
</section>
</body>
</html>

Problem is that when the content section contains enough content to overflow the height of it, instead of scrolling the content stretches it instead. I had hoped that floating the contents might help, but no good there either.

Any ideas?

A: 

Even if you only have to support newer browsers, I think there's a solution that can do all browsers (or at least most). Approach it as a "footer push" solution. For instance:

CSS:

* {
margin: 0;
}
html, body {
height: 100%;
}
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -4em;
}
.footer, .push {
height: 4em;
}

HTML:

<html>
    <head>
        <link rel="stylesheet" href="layout.css" ... />
    </head>
    <body>
        <div class="wrapper">
            <div class="header"></div>
            <div class="article"></div>
            <div class="push"></div>
        </div>
        <div class="footer">
            <p>Copyright (c) 2008</p>
        </div>
    </body>
</html>

So, now the header and footer are a set size, the middle (called the article) will fill the screen unless there's more content, in which case it will stretch. If you modify, be careful to notice the position of the wrapper div, which encapsulates the header and the body, but not the footer.

bpeterson76
Just missing the scrolling in the middle. The middle should stretch the content to fit the page, but if the content inside the middle is too large for this, the middle div should scroll, not the whole page.
Nick Spacek