Click here to get back home

Adjust height base on the the height of the browser window.

 HomeNewsGroups | Search | About
 comp.infosystems.www.authoring.html    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Adjust height base on the the height of the browser window. Q. John Chen 10-20-2006
Posted by Q. John Chen on October 20, 2006, 4:23 pm
Please log in for more thread options


I have a page contains a table (e.g a 3-row table). The middle row is
for the content and the bottom row is for footer notes.

When the middle row does not have much info, the footer goes way too
high up. How can I automatically adjust the height of the middle row
when a user re-size the browser window.

Or, how can specify a minimum height so at least the footer is a
footer?

It seems to me that I can use a div. But I tried several things and
just can get it to work.


THX


Posted by Ben C on October 20, 2006, 5:42 pm
Please log in for more thread options


> I have a page contains a table (e.g a 3-row table). The middle row is
> for the content and the bottom row is for footer notes.
>
> When the middle row does not have much info, the footer goes way too
> high up. How can I automatically adjust the height of the middle row
> when a user re-size the browser window.
>
> Or, how can specify a minimum height so at least the footer is a
> footer?
>
> It seems to me that I can use a div. But I tried several things and
> just can get it to work.

You might think setting height: 100% on the table would work, but 100%
here means "100% of the height of the containing block", and the table's
containing block is the body (in a simple example) whose height depends
on its content. For the content to ask for a percentage of that height
is circular, so the percentage height is treated as "auto".

But if we make the table's containing block a positioned box whose
containing box is the viewport (which it is in the absence of positioned
ancestors), and whose height is 100% of the viewport, the percentages can
be resolved:

div
{
position: absolute;
height: 100%; /* of the viewport */
}

table
{
height: 100%; /* of the div, and therefore also of the viewport */
}

<body>
<div>
<table>
...
</table>
</div>
</body>

This works in Firefox and Opera but unfortunately not Konqueror. I
haven't tried IE.

An alternative is if you can make your footer itself be a div (if it
must be a table row, the div can contain a table containing the row),
then you can just put that div at the bottom of the viewport with
absolute positioning:

div.footer
{
position: absolute;
bottom: 0px;
left: 0px;
right: 0px;
}

Posted by Q. John Chen on October 23, 2006, 2:40 pm
Please log in for more thread options


Tried on IE and it does not work either.

When I tried div.footer, Then there is another problem when there are
too many content in the middle.

Thanks

John


Posted by Ben C on October 23, 2006, 5:17 pm
Please log in for more thread options


> Tried on IE and it does not work either.
>
> When I tried div.footer, Then there is another problem when there are
> too many content in the middle.

Do you mean the way div.footer ends up on top of the content? And then
when you scroll up, it moves up with the page.

It sounds like what you want is a footer at the bottom of the viewport
if the body height is less than the viewport height, but at the bottom
of the content area if it is.

I can't think of a way to do this without scripting. You could try this,
and if it's what you want then Google for the IE equivalents for DOM 0
things like window.innerHeight.

<script type="text/javascript">
function placeFooter()
{
var body = document.getElementsByTagName("body")[0];

if (body.offsetHeight > window.innerHeight)
{
var footer = document.getElementById("footer");
footer.style.bottom = "auto";
}
}
window.onload = placeFooter;
</script>
<style type="text/css">
#footer
{
position: absolute;
background-color: red;
color: yellow;
bottom: 0px;
}
</style>
</head>
<body>
content
...
<div id="footer">
footer
</div>
...

Similar ThreadsPosted
Make textboxs height = the height of the cell it's in minus (n)px August 6, 2004, 6:37 am
max height for tr? May 15, 2006, 1:48 pm
CSS design and 100% height September 16, 2004, 2:30 am
there is no attribute "HEIGHT" November 10, 2004, 6:27 pm
div tag height minimum in IE May 14, 2005, 11:33 am
Doing without table height January 6, 2005, 4:38 pm
simple height 20% February 6, 2006, 3:07 pm
Problems with min-height November 15, 2006, 3:38 pm
fieldset height February 13, 2007, 10:03 am
div tag with height in percentage March 5, 2008, 6:04 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap