当用户调整浏览器</div>时,获取<div>以调整大小

时间:2010-08-13 04:05:12

标签: css browser html scroll resize

我希望使用浏览器更改div的宽度和高度,因为当用户更改其浏览尺寸时,浏览器的宽度和高度会发生变化。

根据答案建议添加代码

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

结果如下:

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

1 个答案:

答案 0 :(得分:3)

正确的解决方案取决于页面的布局。如果您只想填写一个div浏览器窗口,我发现这个CSS是最简单的解决方案:

#theDiv { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }