Solved

div tag & 100% height

Posted on 2004-08-26
11
9,399 Views
Last Modified: 2013-11-19
"simple" question: how do I get content to fill the remaining 100% height of a page and have scrollbars?

I'm trying to get a layout to look like it's in a frameset, but I don't want to use frames...ie I want the top half of the layout to stay where it is on the screen and I want the bottom half (well the bottom-right actually) to have scrollbars attached to it...and I don't want to use iframes.

I've been trying to get it to work with div tags, no luck in any DTD.  And I can't get tables to show scrollbars in TD cells.

anyway, this should hopefully explain it a bit better:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<style>
BODY,HTML{
      height: 100%;
      width:  100%;
}
</style>
</HEAD>

<BODY>
<div style="height:100%;border:1px solid #000000;">sample dummy data<br />.<br />.<br />.<br />.<br />
<div style="height:100%;border:1px solid #000000;overflow:auto;">I want this div to extend to the bottom of the window and only create scrollbars in itself, not the body or html elements nor it's parent div.  And just saying "overflow:hidden" in the body or html isn't an option cause then the content is lost  :-)</div>
</div>
</BODY>
</HTML>
0
Comment
Question by:cwolves
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 9

Author Comment

by:cwolves
ID: 11903448
oh, and has to work in IE & Mozilla
0
 
LVL 19

Expert Comment

by:webwoman
ID: 11903536
Overflow will work -- but there has to be enough content to force the scrollbar. Also, set the height in PIXELS or don't set it at all -- 100% won't generate scrollbars.

You DO NOT need br with the divs, and you really should set the styles separate from the div. Also, it would probably work better if you put a container div around the one you want scrollbars on.
0
 
LVL 18

Expert Comment

by:bruno
ID: 11903562
try this:






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

<html>
<head>
    <title></title>
   
 
    <style type="text/css" media="screen" title="SCREENstyle">
    body {
        height: 90%;
    }
   
#header {
    height: 20%;
    border: 1px solid black;
}

#content {
    height: 80%;
    border: 1px solid black;
    overflow: auto;
    font-size: 50px;
}
    </style>    
    <link rel="stylesheet" media="print" href="style_print.css" title="PRINTstyle" type="text/css" />
   
</head>

<body>

<div id="header">sample dummy data</div>

<div id="content">
I want this div to extend to the bottom of the window and only create scrollbars in itself, not the body or html elements nor it's parent div.  And just saying "overflow:hidden" in the body or html isn't an option cause then the content is lost  :-)
<br />
hi
<br />
I want this div to extend to the bottom of the window and only create scrollbars in itself, not the body or html elements nor it's parent div.  And just saying "overflow:hidden" in the body or html isn't an option cause then the content is lost  :-)
<br />
hi
<br />
I want this div to extend to the bottom of the window and only create scrollbars in itself, not the body or html elements nor it's parent div.  And just saying "overflow:hidden" in the body or html isn't an option cause then the content is lost  :-)
<br />
hi
</div>


</body>
</html>
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:bruno
ID: 11903700
sorry, missed one thing - try this one:





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

<html>
<head>
    <title></title>
   
   
    <style type="text/css" media="screen" title="SCREENstyle">
html, body {
        height: 95%;
    }
   
#header {
    height: 20%;
    border: 1px solid black;
}

#content {
    height: 80%;
    border: 1px solid black;
    overflow: auto;
    font-size: 50px;
}
    </style>    
   
</head>

<body>

<div id="header">sample dummy data</div>

<div id="content">
I want this div to extend to the bottom of the window and only create scrollbars in itself, not the body or html elements nor it's parent div.  And just saying "overflow:hidden" in the body or html isn't an option cause then the content is lost  :-)
<br />
hi
<br />
I want this div to extend to the bottom of the window and only create scrollbars in itself, not the body or html elements nor it's parent div.  And just saying "overflow:hidden" in the body or html isn't an option cause then the content is lost  :-)
<br />
hi
<br />
I want this div to extend to the bottom of the window and only create scrollbars in itself, not the body or html elements nor it's parent div.  And just saying "overflow:hidden" in the body or html isn't an option cause then the content is lost  :-)
<br />
hi
</div>


</body>
</html>
0
 
LVL 9

Author Comment

by:cwolves
ID: 11903711
webwoman - 100% will generate scrollbars once the content gets beyond the height of the parent element.  And the <br> tags are for the sample content!

brunobear - the top content is a fixed height (ie a banner for a page).  can't use % on it  :-/
0
 
LVL 18

Expert Comment

by:bruno
ID: 11903754
Ok, so change it to a fixed height.  you'll need to play with the numbers a bit yourself, i can't do it all for you without all your content - but you should be able to figure it out from here.





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

<html>
<head>
    <title></title>
   
   
    <style type="text/css" media="screen" title="SCREENstyle">
html, body {
        height: 95%;
    }
   
#header {
    height: 100px;
    border: 1px solid black;
}

#content {
    height: 88%;
    border: 1px solid black;
    overflow: auto;
    font-size: 50px;
}
    </style>    
   
</head>

<body>

<div id="header">sample dummy data</div>

<div id="content">
I want this div to extend to the bottom of the window and only create scrollbars in itself, not the body or html elements nor it's parent div.  And just saying "overflow:hidden" in the body or html isn't an option cause then the content is lost  :-)
<br />
hi
<br />
I want this div to extend to the bottom of the window and only create scrollbars in itself, not the body or html elements nor it's parent div.  And just saying "overflow:hidden" in the body or html isn't an option cause then the content is lost  :-)
<br />
hi
<br />
I want this div to extend to the bottom of the window and only create scrollbars in itself, not the body or html elements nor it's parent div.  And just saying "overflow:hidden" in the body or html isn't an option cause then the content is lost  :-)
<br />
hi
</div>


</body>
</html>
0
 
LVL 9

Author Comment

by:cwolves
ID: 11903789
putting a % other than 100 on the bottom div is a hack, no offense  :-).

if someone has a browser open that's shorter, the content overflows off the page.  If their browser is taller it doesn't fill the page.
0
 
LVL 31

Accepted Solution

by:
seanpowell earned 250 total points
ID: 11903969
Are you looking for something like this?

http://www.pdgmedia.com/ee/cwolves.html
0
 
LVL 9

Author Comment

by:cwolves
ID: 11904278
something like that  :-)

what's with the +22 on the offsetheight?
0
 
LVL 31

Expert Comment

by:seanpowell
ID: 11904413
It allows for this, set in the header div:

border:1px solid #666666;
padding:10px;

As you add padding and border width to the div, you have to add it to the offestHeight to counteract it - so: 10 + 10 + 1 + 1.

And thanks for the A ;-)
0
 
LVL 9

Author Comment

by:cwolves
ID: 11904450
cool  :-)  the bottom div is absolutely positioned on my page, so I'm just pulling the offsetHeight & offsetWidth of that:

<script type="text/javascript">
<!--
function getWindowHeight() {
      var wh = (typeof(window.innerHeight)=='number')?window.innerHeight:(document.documentElement && document.documentElement.clientHeight)?document.documentElement.clientHeight:(document.body && document.body.clientHeight)?document.body.clientHeight:0;
      var ww = (typeof(window.innerWidth)=='number')? window.innerWidth: (document.documentElement && document.documentElement.clientWidth) ?document.documentElement.clientWidth: (document.body && document.body.clientWidth) ?document.body.clientWidth:0;
      return {h:wh, w:ww};
}

function setMain() {
      if (document.getElementById) {
            var windowHeight = getWindowHeight();
            if (windowHeight.h > 0) {
                  var cE = document.getElementById('body');

                  cE.style.height = (windowHeight.h - cE.offsetTop)  + 'px';
                  cE.style.width  = (windowHeight.w - cE.offsetLeft) + 'px';
            }
      }
}

window.onload = window.onresize = function(){setMain();}

//-->
</script>

and you're welcome  :-)

thx for the answer.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question