tags:

views:

13633

answers:

6

I have a wrapper div which contans 2 divs next to each other. Above this container I have a div that contains my header. The wrapper div must be 100% minus the height of the header. The header is about 60 px. This is fixed. So my question is: how do I set the height my wrapper div to be 100% minus the 60 px?

<div id="header"></div>
<div id="wrapper">
  <div id="left"></div>
  <div id="right"></div>
</div>
+6  A: 

If you need to support IE6, use JavaScript so manage the size of the wrapper div (set the position of the element in pixels after reading the window size). If you don't want to use JavaScript, then this can't be done. There are workarounds but expect a week or two to make it work in every case and in every browser.

For other modern browsers, use this css:

position: absolute;
top: 60px;
bottom: 0px;
Aaron Digulla
The site is only IE 7 compatible. When I use height: 100% and top: 60px; I still het a scrollbar. I can scroll 60px down.
Martijn
Don't specify a height, use top and bottom and let the browser calculate the height.
Aaron Digulla
But I want my page to have a max height of 100% minus 60px; If the content is larger than that, I want scrollbars in the div by using overflow: scroll;
Martijn
For a scrollbar, add a div inside of wrapper that fills it completely and make that overflow: scroll;
Aaron Digulla
Note that due to bugs in IE7, this might still fail. If you can't get it to work, use JavaScript. I know, you don't like it, but weight it against a week of work struggling with odd bugs.
Aaron Digulla
So, i should use javascript to set the height of #left and #right and apply an overflow to it?
Martijn
Sorry, I didn't make myself clear enough. I want a scrollbar in #left and #right
Martijn
Ah ... just set the height of both to 100%. But that might not work if you float them. If you need them next to each other, put them into a table. That's ugly but the most simple solution. In that case, you might be able to do without the wrapper div (just replace it with the table).
Aaron Digulla
I don't get why I should use tables. The must always be a 100 percent. Even if the content is smaller. The scrollbars have stick to the bottom of the viewport. Or maybe you can give me an example?
Martijn
I've been looking for this for ages - thanks!
What
A: 

Use an outer wrapper div set to 100% and then your inner wrapper div 100% should be now relative to that.

I thought for sure this used to work for me, but apparently not:

<html>
<body>
<div id="outerwrapper" style="border : 1px solid red ; height : 100%">
<div id="header" style="border : 1px solid blue ; height : 60px"></div>
<div id="wrapper"  style="border : 1px solid green ; height : 100% ; overflow : scroll ;">
  <div id="left" style="height : 100% ; width : 50% ; overflow : scroll; float : left ; clear : left ;">Some text 

on the left</div>
  <div id="right" style="height : 100% ; width 50% ; overflow : scroll; float : left ;">Some Text on the 

right</div>
</div>
</div>
</body>
</html>
Cade Roux
Can give an example of that. I don't understand
Martijn
I posted what I was thinking of, but I can't get it working this early/late. Maybe if I get a little more sleep.
Cade Roux
Okee, anyway thx for the effort :)
Martijn
+9  A: 

Here is a working css, tested under Firefox / IE7 / Safari / Chrome / Opera.

* {margin:0px;padding:0px;overflow:hidden}
div {position:absolute}
div#header {top:0px;left:0px;right:0px;height:60px}
div#wrapper {top:60px;left:0px;right:0px;bottom:0px;}
div#left {top:0px;bottom:0px;left:0px;width:50%;overflow-y:auto}
div#right {top:0px;bottom:0px;right:0px;width:50%;overflow-y:auto}

"overflow-y" is not w3c-approved, but every major browser supports it. Your two divs #left and #right will display a vertical scrollbar if their content is too high.

For this to work under IE7, you have to trigger the standards-compliant mode by adding a DOCTYPE :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
            "http://www.w3.org/TR/html4/strict.dtd"&gt;
<html>
<head>
<title></title>
<style type="text/css">
    *{margin:0px;padding:0px;overflow:hidden}
    div{position:absolute}
    div#header{top:0px;left:0px;right:0px;height:60px}
    div#wrapper{top:60px;left:0px;right:0px;bottom:0px;}
    div#left{top:0px;bottom:0px;left:0px;width:50%;overflow-y:auto}
    div#right{top:0px;bottom:0px;right:0px;width:50%;overflow-y:auto}
</style>
</head>
<body>
<div id="header"></div>
<div id="wrapper">
  <div id="left"><div style="height:1000px">high content</div></div>
  <div id="right"></div>
</div>
</body>
Alsciende
It works in FF, but i don;t get it work under IE7. I only see 'Header' Code:<div id="header">Header</div><div id="wrapper"> <div id="left">Left</div> <div id="right">Right</div></div>
Martijn
Did you trigger the standards compliant mode ? I'll add an example page in my response.
Alsciende
A: 

This doesn't exactly answer the question as posed, but it does create the same visual effect that you are trying to achieve.

<style>

body {
  border:0;
  padding:0;
  margin:0;
  padding-top:60px;
}

#header {
  position:absolute;
  top:0;
  height:60px;
  width:100%;
}

#wrapper {
  height:100%;
  width:100%;
}
</style>
Noel Walters
A: 

thanks man it helped me very much

rajkumbh
A: 

great one... now i have stopped using % he he he... except for the main container as shown below:

<div id="divContainer">
    <div id="divHeader">
    </div>
    <div id="divContentArea">
        <div id="divContentLeft">
        </div>
        <div id="divContentRight">
        </div>
    </div>
    <div id="divFooter">
    </div>
</div>

and here is the css:

#divContainer {
    width: 100%;
    height: 100%;
}
#divHeader {
    position: absolute;
    left: 0px;
    top: 0px;
    right: 0px;
    height: 28px;
}
#divContentArea {
    position: absolute;
    left: 0px;
    top: 30px;
    right: 0px;
    bottom: 30px;
}
#divContentLeft {
    position: absolute;
    top: 0px;
    left: 0px;
    width: 250px;
    bottom: 0px;
}
#divContentRight {
    position: absolute;
    top: 0px;
    left: 254px;
    right: 0px;
    bottom: 0px;
}
#divFooter {
    position: absolute;
    height: 28px;
    left: 0px;
    bottom: 0px;
    right: 0px;
}

i tested this in all known browsers and is working fine. Are there any drawbacks using this way?

Jayaveer