We help IT Professionals succeed at work.

How can I extend a div to the bottom of the page?

Trel
Trel used Ask the Experts™
on
Take for instance this layout: http://www.krahs-emag.com/test06d2.php

The white line is a left border on a containing div, if my content does not reach the end of the page, the containing div does not either.

How can I make that div extend to the bottom of the page if the content does not make it reach there?

I want to add that I need this to stay XHTML strict.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
look at the following two samples of code.

1) This is something similar to what you have. The div spans just one column

***************
<html>
<div style="background:red" >hello world</div>
<body>
</body>
</html>
*******************************
2) This is the modified code, to have a fixed height

************************************
<html>
<div style="background:red;height:80%" >hello world</div>
<body>
</body>
</html>
*************************************
Just a word of caution though.
if you set the height of the div defined by the class "content-box", you would not be able to get the desired effect.

the key is to understand, that the percentages work relative to the parent div. so you would need to set this percentage in the class "right-column" and also in "content-box"

Lemee know if you need any clarifications

~Gary

Author

Commented:
I'm not sure I understand that.
Also, wouldn't that cause a problem if the content inside exceeded the 100% of the page and needed to cause a scroll bar?

Author

Commented:
Wait, another quesition, I'm trying to set the wrap div to do it, not the inner left and right ones. That one is

<body>
<div class="wrap">
rest of the page
</div>
</body>

If I set the wrap class to a height:100%; there is no change at all.
to answer your second question, no it wont cause a problem. the height percentage attribute is overridden if the content is more than the allowed percentage. it automatically extends itself.

hopefully the following two examples should illustrate better on what i mean.
1)
********************
<html>
<div>
    <div style="background:red;height:80%" >hello world</div>
</div>
<body>
</body>
</html>
********************

2)
********************
<html>
<div style="background:blue;height:100%">
    <div style="background:red;height:80%" >hello world</div>
</div>
<body>
</body>
</html>
********************

In the first example, the div does not span 80% of the page. Its height is set to 80% of its parent div. Since there is no height attribute set for the parent div, the child div is still as high as its parent div.

now consider the second piece of code.
The first div has the height set to 100%. so it spans the entire page.
The child div has the height set to 80%, so it spans 80% of the parent div's height.

To summarize, if you have nested div's as in the examples above, all the position elements, namely 'position', 'top', 'left', 'height', 'width' etc, they are all with respect to their parent div tags.

Hope this helps
yup...i saw your page structure. you would need to set the height:100%  to your right-column, then to your content-wrapper-b, and then to your content-box

Author

Commented:
It made absolutely no difference :(

Without the height:100% : http://www.krahs-emag.com/test06d3.php
With the height:100% : http://www.krahs-emag.com/test06d4.php

no visible difference
Hi Trel,

You'll need to use min-height and also set 100% to the body and html, because you are specifying 100% of the parent, and body, html is the parent, and tell IE6 to use height in the conditional comment.

http://communitymx.com/content/article.cfm?page=2&cid=BAD95

Take a look at this example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
 "http://www.w3.org/TR/html4/strict.dtd">
<head>
<title>Filling the window</title>
<style type="text/css">
html, body {height: 100%;}
body {margin: 0;padding: 0;background: #fff;color: #000;}
#wrap {min-height: 100%; width:300px;padding: 10px;background: #CCFFCC;}
</style>
<!--[if lte IE 6]>
<style type="text/css">
#wrap {height: 100%;}
</style>
<![endif]-->
</head>
<body>
<div id="wrap">
<p>Fill the window!</p>
<p>Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet </p>
</div>
</body>
</html>
but you did not make the complete changes...after changing the class wrap to have height:100%, you also need to have height:100% in the class ".right-column"

right now, it is as below:

.right-column
{
      width: 80%;
      float: left;

}

~Gary

Author

Commented:
@Daydreams, I'll try that now, will that invalidate my CSS?
@harshgrover, it's the second url that I modified: http://www.krahs-emag.com/test06d4.php
yup...i looked at the second url. and it did not have the height:100% set. it only had the width set

Author

Commented:
@harshgrover, I was looking at my offline copy, sorry, it still didn't make a difference.

@daydreams, that worked, what exactly is the need for the IE conditional, it's working fine in IE6
Trel, for the conditional comments, IE 6.0 and lower does not support min-height, (although IE7 may support it; I haven't tested). However, its treatment of the height property — where it respects your height until you add more content than the height can accommodate, at which point it expands the height regardless of your desired value — is exactly how min-height is supposed to function.

More info on conditional comments:

http://alastairc.ac/2006/05/conditional-comments-in-css/

Author

Commented:
Thanks, it was working on one file and not the other, the one it was working with had extra padding on the bottom I forgot to remove so it did extend, on the one that wasn't working, that IE thing fixed it, thanks :)