Forum Moderators: not2easy

Message Too Old, No Replies

css div height 100%

         

drooh

6:12 pm on Mar 22, 2008 (gmt 0)

10+ Year Member



<div style="width: 800px; height: 600px"></div>
<div style="height: 100%; background-color: brown;"></div><!-- I want this div to continue down to the end of the screen -->

what is the solution to make the lower div stretch down to fill up the rest of the page?

Using xhtml transitional or strict and hopefully not using tables. Can someone explain?

I've tried searching for about 2 hrs through other topics and can not seem to get a working solution.

DrDoc

7:32 pm on Mar 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<div style="height: 100%; background-color: brown;">
<div style="width: 800px; height: 600px"></div>
</div>

If you put the "600px" div inside the "100%" div, you'll get what you're asking for. "100%" is 100% of the parent element or the viewport, whichever comes first. By stacking the divs on top of each other, you will get a total height of 100% + 600px. By nesting them, the "brown" div will take up 100% of the viewport, just as you want, and also reducing the viewable area with 600px due to the child div taking up that space.

drooh

3:54 am on Mar 24, 2008 (gmt 0)

10+ Year Member



what about like this?

<!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" xml:lang="en" lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
</head>
<body>
<div style="height: 100%; background-color: brown;">
<div style="width: 800px; height: 600px; background-color: green;"></div>
</div>
</body>
</html>

venti

5:19 am on Mar 24, 2008 (gmt 0)

10+ Year Member



Make sure all the parent tags also have a 100% height. Meaning you must assign the 100% height to the body, html, and any other nested tags you may have.

html { height: 100%; }
body { height: 100%; }