Solved

div tag & 100% height

Posted on 2004-08-26
11
9,397 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
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

832 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