Forum Moderators: not2easy

Message Too Old, No Replies

Text overlaps DIV

         

Webbie25

11:03 am on Jul 5, 2004 (gmt 0)

10+ Year Member



Hi!

Another problem.
I have a centered DIV.
It must be 100% height.
Also body margins must be 20 pixels.

If content text is higher than 100%. The content DIV must expand.
Body margin must stay 20px.

The code below is almost oke, but 2 problem occur:
- IE: bottom-margin of 20px is lost, when content is more than 100%
- Mozilla: Text overlaps DIV. The DIV wont expand!

Here the code:
Can anyone help me...is there another solution?
-----------------------------------------------
<!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>B2S</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css" media="screen">
html,
body {
background:#505962 url(../img/bg/body.jpg) repeat-y center;
height:100%;
margin:0;
padding:0
}

#container {
background:#FFF url(../img/bg/container.gif) repeat-y right;
bottom:20px;
left:0;
margin:0 auto;
position:absolute;
right:0;
top:20px;
width:604px
}
</style>
<!--[if IE]>
<style type="text/css" media="screen">
#container {
height:expression(document.body.clientHeight - 40 + "px");
left:expression(document.body.clientWidth / 2 - 302 + "px")
}
</style>
<![endif]-->
</head>

<body>
<div id="container">
test<br />
test<br />
test<br />
test<br />
test<br />
test<br />
test<br />
test<br />
test<br />
test<br />
test<br />
test<br />
test<br />
test<br />
</div>
</body>
</html>
--------------------------------------------------------
Thanks!

createErrorMsg

3:13 pm on Jul 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For starters, axe the height: 100% in the body rule dec. The body cannot be anything BUT 100% and you may be causing problems by trying to explicitly tell the browser (especially IE) how tall to make that element.

So take the 100% height out of the body element and put it, instead, into the #container rule dec. Set your margins and padding in BODY to 0, then set margins and padding on #CONTAINER to whatever you want.

Next, lose the top:20 and bottom:20 in the #CONTAINER rule. If you want a 20px margin, use margin instead.

Try this set up:
body, html {
margin: 0;
padding:0;
border:0;
background: whatever;
}
#container {
width: 600px;
height: 100%;
margin: 20px auto;
}

Keep in mind, however, that the 100% height is probably not even necessary, unless this container is on a page with other <divs> that are doing other things. WHy? Because one <div> holding content, not inside another <div> or <table> will automatically take up 100% of the available space. In other words, 100% height = the total height of all content. So you should be able to get rid of the height altogether.

If your problem is that the body background image is being overlapped, it's probably because you've got "repeat-y" and "center" (and "right" in #CONTAINER) in the wrong place. CSS shorthand rule declarations are very specific and picky. It HAS to be...
background: color url(image) position repeat;
...in that order. As you have it now, it's probably only displaying the image one time, at the top of the page/container.

Hope it helps.

Webbie25

7:02 am on Jul 6, 2004 (gmt 0)

10+ Year Member



Unfortunately...this doesn't work. I tried it allready. It was also my first idea. Thiis makes sense, so I typed the same code. But you have to declare height:100% in body and html, because otherwise the #container will not expand to the bottom.

But if you do declare html,body {height:100%} the margins of 20px (#container) cause the page to scroll in both IE and Firefox.

Any other suggestions?

createErrorMsg

11:50 am on Jul 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Put another <div> inside #container and give the margins to it? Just guessing here.

Webbie25

12:21 pm on Jul 6, 2004 (gmt 0)

10+ Year Member



No sorry...that has the same effect....

ktwilight

3:21 am on Jul 8, 2004 (gmt 0)

10+ Year Member



how 'bout putting padding 20px in body, html?

Webbie25

6:44 am on Jul 8, 2004 (gmt 0)

10+ Year Member



Been there...done that. Produces also a scrollbar...sorry :)