Forum Moderators: not2easy

Message Too Old, No Replies

Floated, Centered, 100% Height Div Issue

         

Drath

4:18 pm on May 14, 2009 (gmt 0)

10+ Year Member



As I understand it, it's quite impossible (from what I've TRIED to search for around the internet) to get floated elements to go to 100% height on any browser. To give an example, here is the full code:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
body {
margin:0 auto;
text-align:center;
background:#999;
height:100%;
}
#container {
width:1000px;
margin:0 auto;
text-align:center;
}
#left, #right {
float:left;
width:25px;
height:100%;
background:#444;
}
#center {
float:left;
width:950px;
height:100%;
background:#fff;
}
.clr {
clear:both;
}
</style>
<body>
<div id="container">
<div id="left">a</div>
<div id="center">This is the center</div>
<div id="right">b</div>
<br class="clr" />
</div>
</body>
</html>

As you can see, they are not being stretched to 100% height. I am wondering if there is maybe another way to do this without using floats? I experimented using position absolutes, but the layout kept breaking and breaking even more on IE. Anybody have any ideas?

holyhttp

4:09 am on May 20, 2009 (gmt 0)

10+ Year Member



You could use "display:inline" rule instead of floating in this instance.

swa66

8:25 am on May 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



100% height means the element gets the height of the direct parent element provided your CSS sets explicitly the height of the element (and is different from auto [which is the default]).

There is one exception: the root has the height of your viewport.

So adding


html, body, container {
height: 100%
}

will at first looks fix your problem, but in reality it's not what you seek as it'll break the moment your content gets longer than the viewport, and you've no way to cater for footers or headers.

It's much easier to forget the idea of having your columns of equal height and fake the background effect by having an image on the parent nd stretch that one to encompass the floated columns.
Add ign a min-height to make sure it fills the screen can then be done and the footer can easily be positioned at the bottom.