Solved

div tag & 100% height

Posted on 2004-08-26
11
9,396 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Glyph icons in Bootstrap 3 4 37
Bootstrap 3 with accordion menu 2 44
Using Classic ASP inside HTML pages 2 55
Problem with a CSS in a page 2 25
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.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

937 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

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now