Solved

div tag & 100% height

Posted on 2004-08-26
11
9,395 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
Comment Utility
oh, and has to work in IE & Mozilla
0
 
LVL 19

Expert Comment

by:webwoman
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 18

Expert Comment

by:bruno
Comment Utility
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
Comment Utility
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
Comment Utility
Are you looking for something like this?

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

Author Comment

by:cwolves
Comment Utility
something like that  :-)

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

Expert Comment

by:seanpowell
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
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 …
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

744 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

17 Experts available now in Live!

Get 1:1 Help Now