Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

div tag & 100% height

Posted on 2004-08-26
11
Medium Priority
?
9,404 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 1000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
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.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

963 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