Forum Moderators: not2easy

Message Too Old, No Replies

Div seems to be pushing its parent div larger

My friend asked me to do a simply problem: I can't do it!

         

SethCall

6:14 pm on Sep 22, 2003 (gmt 0)

10+ Year Member



My friend's problem:

Simply make a div have a 20px top margin and take up the rest of the height of the screen, WITHOUT making the div larger than 100% of the height of the screen (i.e., make the vertical scroll bar not show up)

Here is the code i think should work.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>
<head>
<title>Silly div</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<style type="text/css">
html
{
width:100%;
height:100%;
}
body
{
width:100%;
height:100%;
margin:0px;
padding:0px;
border:0px;
background-color:#000000;
}

div
{
position:static;
}

#wrapper
{
background-color:#989898;
width:100%;
height:100%;
}

#content
{
margin-top:20px;
background-color:#dedede;
height:100%;
width:80%;
margin-left:auto;
margin-right:auto;
}

</style>
</head>

<body>

<div id="wrapper">

<div id="content"></div>

</div>

</body>

</html>

*tufts of hair fall lazily to the ground*

Reflection

6:17 pm on Sep 22, 2003 (gmt 0)

10+ Year Member



You could try using padding-top instead of margin if its only the content of the div that needs to be pushed down.

SethCall

7:56 pm on Sep 22, 2003 (gmt 0)

10+ Year Member



well, I dont want just the content to be pushed down, but the div itself, so that you should have a background color change at 20px down from the top (first the background of the "wrapper" should be visible, then the background of content).

I did try your change though (Changing margin-top to padding-top ) and it is even more wacky.

In that case, the inner div (content) actualy flows out of its container (wrapper).

Although I know this can happen with images or text, im unused to it occurring in this instance, here no content is pushing it larger. Even so, changing its overflow property to "hidden" does nothing to the overflowing over the bottom of the wrapper div.

Thank you, though, Reflection

Reflection

10:52 pm on Sep 23, 2003 (gmt 0)

10+ Year Member



Would changing the top margin to a percentage value and then subtracting that from the 100% height work, or do you specifially need 20px?

This thread [webmasterworld.com] from the css library might have some info in it that could help you.

MonkeeSage

11:12 am on Sep 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How about...

html
{
width:100%;
height:100%;
margin-bottom: -20px;
}

Add some to the top; chop some from the bottom. :)

Jordan