Forum Moderators: not2easy

Message Too Old, No Replies

2 column DIV lay-out with header: height:100% problem

Two sollutions, but none work in Mozilla and Internet Explorer

         

PaulKruijt

12:53 pm on Mar 5, 2004 (gmt 0)

10+ Year Member



Hello.

I've read a couple of topics about my problem, but none had a perfect solution.

Here's the deal:
Like a lot of people, i've got a 2 column (menu and content DIV) lay-out with a header and an footer. All are in a container DIV, centered on the page. The problem is that the DIV's won't expand on the page 100%. The container (page) is set to height:100%. Both menu and content DIV to. The header DIV has a fixed height.

The problem is that in Mozilla (Firefox) the container DIV doesn't scale width the inner DIV's.

Two solutions I read
1. Place a spacer DIV below content DIV with clear:both

---> This doesn't work for my lay-out

2. Give container DIV padding-bottom. (height=size of fixed header+fixed footer)

---> This works! But when I display it in Internet Explorer? This has the same problem I had first on Mozilla. Container DIV lies behind menu and content DIV.

-----------------------------------------------------
Can anyone help me?
Here's my code:
-----------------------------------------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Website</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
html,body {
background:#AAA;
height:100%;
margin:0;
padding:0;
width:100%
}

#page {
background:#AAA;
border-bottom:1px solid #000;
border-left:1px solid #FFF;
border-right:1px solid #000;
border-top:1px solid #FFF;
height:100%;
margin:0 auto;
padding-top:4px;
width:776px;
voice-family:"\"}\"";
voice-family:inherit;
width:774px
}

#header {
background:#174D88;
border-bottom:1px solid #FFF;
border-left:1px solid #000;
border-right:1px solid #FFF;
border-top:1px solid #000;
clear:both;
font-size:9px;
height:21px;
margin:0 4px 4px 4px;
padding:3px 0 0 6px;
width:766px;
voice-family:"\"}\"";
voice-family:inherit;
height:16px;
width:758px
}

#menu {
background:#BBB;
border-bottom:1px solid #FFF;
border-left:1px solid #000;
border-right:1px solid #FFF;
border-top:1px solid #000;
display:inline;
float:left;
height:100%;
margin:0 0 4px 4px;
width:137px;
voice-family:"\"}\"";
voice-family:inherit;
width:135px
}

#content {
background:#DDD;
border-bottom:1px solid #FFF;
border-left:1px solid #000;
border-right:1px solid #FFF;
border-top:1px solid #000;
display:inline;
float:left;
height:100%;
margin:0 0 4px 4px;
width:625px;
voice-family:"\"}\"";
voice-family:inherit;
width:623px
}

#footer {
background:#174D88;
border-bottom:1px solid #FFF;
border-left:1px solid #000;
border-right:1px solid #FFF;
border-top:1px solid #000;
clear:both;
font-size:9px;
height:21px;
margin:0 4px 4px 4px;
padding:3px 0 0 6px;
width:766px;
voice-family:"\"}\"";
voice-family:inherit;
height:16px;
width:758px
}
</style>
</head>

<body>
<div id="page">
<div id="header"></div>
<div id="menu"></div>
<div id="content"></div>
<div id="footer"></div>
</div>
</body>
</html>

isitreal

6:01 pm on Mar 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



100% height does not refer to the contents of the nested divs, it refers to the browser window height. Mozilla is treating this correctly, you told it that the container is 100% high, so that's what it's making it. Actually you told it that it is 100% + whatever other CSS you have on it, borders, padding, margins etc, that will also make standards compliant browsers make the page always have a vertical scroll bar, since the page is always a pixel or two larger than the height of the window.

Try removing the height declaration for #page and see if that works, although I've seen a lot of people have trouble with this kind of layout here.

PaulKruijt

9:24 pm on Mar 5, 2004 (gmt 0)

10+ Year Member



unfortunately...that doesn't work either...:-(

ergophobe

9:28 pm on Mar 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



ALA has an article on just this topic, as PeteB recently mentioned

[alistapart.com...]

Tom

PaulKruijt

9:47 am on Mar 6, 2004 (gmt 0)

10+ Year Member



NEW PROBLEM
Check out this code in:
- Mozilla
- IE6

Mozilla: Why doesn't the DIV (content) height stretch?
IE: Why doesn't the DIV (menu) height stretch?

note: it works in IE5.5 and IE5.0!

-----------------------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Website</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
#mainWrapper {
background:#AAA;
border-left:1px solid #FFF;
border-right:1px solid #000;
height:200px;
margin:0 auto;
width:776px;
voice-family:"\"}\"";
voice-family:inherit;
width:774px
}

.ie5{} /* IE5.0 hack */

#menu {
background:#BBB;
border-bottom:1px solid #FFF;
border-left:1px solid #000;
border-right:1px solid #FFF;
border-top:1px solid #000;
display:inline;
float:left;
height:100%;
margin-left:4px;
width:137px;
voice-family:"\"}\"";
voice-family:inherit;
width:135px
}

.ie5{} /* IE5.0 hack */

#content {
background:#DDD;
border-bottom:1px solid #FFF;
border-left:1px solid #000;
border-right:1px solid #FFF;
border-top:1px solid #000;
color:#000;
display:inline;
float:left;
font-size:11px;
height:100%;
margin-left:4px;
width:625px;
voice-family:"\"}\"";
voice-family:inherit;
width:623px
}
</style>
</head>

<body>
<div id="mainWrapper">
<div id="menu"></div>
<div id="content">
abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz<br />
</div>
</div>
</body>
</html>

isitreal

3:29 pm on Mar 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your content wrapper has a fixed height of 200px; if you don't want a fixed height with divs, you can't declare a fixed height, I've seen some separate behaviors for how browsers handle this, Opera for example cuts it off, correctly, so does I believe Mozilla, IE tends to let it extend, incorrectly.

A height declaration of 100% in menu and content means that those divs are set to be 200px high. Divs are quite strict about their widths and heights, as soon as you've declared this for its container, that's how high it will be, that is correct behavior. The only way to make a div stretch the way you want is to not set any height on any container of the div, then it will flow down to fit its contents.

The best way to get the behaviors you are looking for, at least one that actually works reliably, and that's to use a table, which always resizes itself to fit its content, except in Opera, from what I've seen, if you declare its height at 100%, that's how high it will be.

When I want one column or cell to always match height with another column or cell no matter how long the page gets, I always use a table, it's the best tag for the job, especially once your page extends off the screen.

lexipixel

6:15 am on Mar 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The HTML below creates a TABLE with a light blue background and 1 pixel border that fills the whole page regardless of browser size.

To see where your HTML is showing up on the screen place your HTML between the <TD> and </TD> tags, (where the "x" is now).

There is a 1 pel border and 8 pel of cellspacing defined, to make the whole screen light blue, (no borders or spacing), change the parameters for
BORDER= and CELLSPACING= to "0". I just set them to 1 and 8 so the effect could be seen.

I realize this is simplistic, but maybe it will help some beginners.

NOTE: w3.org defines "height" in regards to TABLE cell size as a "suggestion", (other browser/HTML settings may take precedence).

<HTML>
<HEAD>
<TITLE>100 Percent Window Size</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TOPMARGIN="0" LEFTMARGIN="0" RIGHTMARGIN="0">
<TABLE border="0" cellspacing="8" cellpadding="0" width="100%" height="100%">
<TR>
<TD bgcolor="#E0E0FF" align="CENTER" valign="MIDDLE" width="100%" height="100%">
x
</TD>
</TR>
</TABLE>
</BODY>
</HTML>

isitreal

3:42 pm on Mar 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



LexiPixel: thanks for pointing out the obvious, use the right tool for the job, a table. It's not simplistic at all, it's the best tag for the problem, and is simply using one of the most powerful tags available in HTML to solve a problem without any headaches or debugging time.

PaulKruijt

5:04 pm on Mar 7, 2004 (gmt 0)

10+ Year Member



yeah tables are the best solution for this problem. I was just wondering if I could get it to work with DIVs.

But if I don't set the HEIGHT of the mainWrapper, then my mainWrapper background isn't visible at all. Due to the floats, the 2 floating DIVs overlay the mainWrapper. WHY GOD?! WHY!? :-P

ORBiTrus

3:30 pm on Mar 8, 2004 (gmt 0)

10+ Year Member



Try putting the two floats w/in yet another floated layer. That resizes the main content pane. However.... do not use height:100% on them. Simulate this by creating two BACKGROUND layers, set both to height:100%, no content, and absolute position (sucks, true). What you should end up with is a 2col layout where it appears that both columns extend to the bottom.... but we all know that appearances can be deceiving.

Note: IE6 will not resize the main content pane unless you specify a height. However, when you do this, the backgrounds recieve the height that was specified for the content div... This is IE only so I'm pretty there must be a way to fix it. The q is how. (atm. I usually just use an image background png in IE only. It works.)