views:

69

answers:

2

I want a div's width and height to change with the browser as the browser's width and height are changed when a user changes their browses dimensions.

Code added based on the answers suggestion

<!doctype html>
<html>
    <head>
    <link rel="shortcut icon" href="/favicon.ico"> 
    <meta charset='UTF-8'>
    <%= stylesheet_link_tag 'application' %>
    <title>Some Company - Terms and Conditions</title>
</head>
<body >
<div>
    some anchor links here go to the content inside the div below
    </div>
   <div style="position: absolute; top: 100; bottom: 0; left: 0; right: 0;overflow:auto;padding:10px;border:1px solid lightblue;">
     content here
    </div>
</body>

Here was the end result:

<!DOCTYPE html>
<html>
<head><title>Terms and Conditions</title></head>
<body>
<a href="#tac20">Terms and Conditions 20</a> | <a href="#tac40">Terms and Conditions 40</a>

    <div style="position:absolute; top: 30px; bottom: 0; left: 0; right: 0;overflow-y:auto;padding:5px;border-top:1px solid lightblue;">
        Terms and Condition 1 <br/>     
        Terms and Condition 2 <br/>
        Terms and Condition 3 <br/>
        Terms and Condition 4 <br/>
        Terms and Condition 5 <br/>
        Terms and Condition 6 <br/>
        Terms and Condition 7 <br/>
        Terms and Condition 8 <br/>
        Terms and Condition 9 <br/>
        Terms and Condition 10 <br/>
        Terms and Condition 11 <br/>        
        Terms and Condition 12 <br/>
        Terms and Condition 13 <br/>
        Terms and Condition 14 <br/>
        Terms and Condition 15 <br/>
        Terms and Condition 16 <br/>
        Terms and Condition 17 <br/>
        Terms and Condition 18 <br/>
        Terms and Condition 19 <br/>
        <a name="tac20">Terms and Condition 20</name> <br/>
        Terms and Condition 21 <br/>        
        Terms and Condition 22 <br/>
        Terms and Condition 23 <br/>
        Terms and Condition 24 <br/>
        Terms and Condition 25 <br/>
        Terms and Condition 26 <br/>
        Terms and Condition 27 <br/>
        Terms and Condition 28 <br/>
        Terms and Condition 29 <br/>
        Terms and Condition 30 <br/>
        Terms and Condition 31 <br/>        
        Terms and Condition 32 <br/>
        Terms and Condition 33 <br/>
        Terms and Condition 34 <br/>
        Terms and Condition 35 <br/>
        Terms and Condition 36 <br/>
        Terms and Condition 37 <br/>
        Terms and Condition 38 <br/>
        Terms and Condition 39 <br/>
        <a name="tac40">Terms and Condition 40</name> <br/>
    </div>
</body>

A: 
<!DOCTYPE html>
<html>
<head>
<style>
html, body {width:100%;height:100%;padding:0;margin:0;}
#v {width:50%;height:50%;display:block;background:#000;color:#fff;}
</style>
</head>

<body>
<div id="v">Fixed, I hope.</div>
</body>
</html>

I just tested it. It indeed does work for height.

flam
Doesn't vertically size properly: http://jsbin.com/ovoka3
strager
I would like to see someone confirm that this will resize the height of a div when the browser is resized
Sam
Actually, this only works in quirks mode.
strager
Sorry, hope this is better (edited my post and a live sample: http://jsbin.com/ufawo3/3)Also please note I read the question before it had been edited. :S
flam
The % height property never works correctly in my experience.
banzaimonkey
+3  A: 

The right solution depends on the layout of the page. If you just have a single div you want to fill the browser window, I find this CSS the easiest solution:

#theDiv { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }
Jacob
You took the words out of my mouth. This method also allows you to add a consistent gap around the div. Sizing in percentages will fluctuate the size of the gap around the div.
Bryan Downing
Yeah it looks good and works too! Check my edit to see what's going on
Sam
I have links above that I always want to be on top for nav
Sam