tags:

views:

70

answers:

5

How would I change this to make the middle div expand vertically to fill the white space?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">

body,td,th {
    font-family: Tahoma, Geneva, Verdana, sans-serif;
}

html,body {
    margin:0;
    padding:0;
    height:100%; /* needed for container min-height */
}

#container {
    position:relative; /* needed for footer positioning*/
    margin:0 auto; /* center, not in IE5 */
    width:100%;

    height:auto !important; /* real browsers */
    height:100%; /* IE6: treaded as min-height*/

    min-height:100%; /* real browsers */
}

#header {
    height: 150px;
    border-bottom: 2px solid #ff8800;
    position: relative;
    background-color: #c97c3e;
}

#middle {
    padding-right: 90px;
    padding-left: 90px;
    padding-top: 35px;
    padding-bottom: 43px;
    background-color: #0F9;
}
#footer {
    border-top: 2px solid #ff8800;
    background-color: #ffd376;
    position:absolute;
    width:100%;
    bottom:0; /* stick to bottom */
}
</style>
</head>

<body>

<div id="container">
    <div id="header">
        Header
    </div>
    <div id="middle">
        Middle
    </div>
    <div id="footer">
        Footer
    </div>
</div>

</body>
</html>
A: 

This is my backup answer:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">

body,td,th {
    font-family: Tahoma, Geneva, Verdana, sans-serif;
}

html,body {
    margin:0;
    padding:0;
    height:100%; /* needed for container min-height */
}

#container {
    height: 100%;
}

#container #header {
    height: 50px;
    background-color:#0F6;
}

#container #middle {
    background-color: #66F;
}

#container #footer {
    height: 20px;
    background-color: #FF3;
}

</style>
</head>

<body>

<!-- Apology note to perfectionists: I'm sorry for using tables, but see this:
    http://stackoverflow.com/questions/1703455/three-row-table-less-css-layout-with-middle-row-that-fills-remaining-space
    A layout done with this table would be impossible with CSS. -->
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="container">
  <tr id="header">
    <td>h</td>
  </tr>
  <tr id="middle">
    <td>m</td>
  </tr>
  <tr id="footer">
    <td>f</td>
  </tr>
</table>


</body>
</html>
David Lawson
A: 
#footer {
    clear: both;
}

That should to the trick. The footer should alway appear below the column with the most content.

Personally I always add a CSS clear class in my templates and use them as breaks

.clear {clear:both;}

Then:

<div id="container">
    <div id="header">
        Header
    </div>
    <div id="middle">
        Middle
    </div>

    <br class="clear" />

    <div id="footer">
        Footer
    </div>
</div>

Tables will cause you more problems than they solve.

danixd
This will only stick the footer below the middel-part. I think what he wants is a footer that always stick to the bottom of the screen unless the expanding content is bigger than the browser height. in which case he wants it to appear beneath the end of the expanding content.
Falle1234
A: 

I think what you are looking for is sometimes called a sticky footer.

This page explains how it is done. What you would do is put your header and expanding content inside the wrapper he mentions.

I hope this helps you get your layout.

Falle1234
This isn't what I'm looking for - no sticky footers I can find have an expanding center.
David Lawson
A: 
$(function(){
    expand();
});

$(window).resize(function(){
    expand();
});

function expand()
{
    $('#timetable').css('minHeight', ($(window).height() - $("#footer").height() - $("#timetable").offset()["top"] - 20) + "px");
    $('#todo').css('minHeight', ($(window).height() - $("#footer").height() - $("#timetable").offset()["top"] - 20) + "px");
    /* if ie, set height*/
}
David Lawson
What are #timetable and #todo? You certainly shouldnt need to set 2 CSS values with Javascript, and I don't believe you need to reset the values everytime the window is resized either. Finally you shouldn't use magic numbers (you subtract 20 at the end of both calculations, without explanation). See my solution.
jackocnr
A: 

You can't get the actual div to expand to fill a gap without Javascript, but you can easily make it appear to do so. Move your rule background-color:#0F9; from #middle to #container. This will give you the behaviour you require (it will fill the gap when there is minimal content, and when there is lots of content it will expand down, pushing the footer with it).

If however you want the Javascript solution, the following code will work. Simply put this in your HTML head section:

<script type="text/javascript">
window.onload = function() {
    var mid = document.getElementById('middle');
    var foot = document.getElementById('footer');
    mid.style.height = ((foot.offsetTop+foot.clientHeight)-(mid.offsetTop+mid.clientHeight))+'px';
};
</script>
jackocnr
sure the background is then filled, but the #middle has not stretched. not what i am looking for soz
David Lawson
The only way you can achieve what you want is with Javascript. I have edited my post with the solution. This should do exactly what you want!
jackocnr