代码之家  ›  专栏  ›  技术社区  ›  Sam å±±

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

  •  2
  • Sam å±±  · 技术社区  · 14 年前

    我希望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 回复  |  直到 14 年前
        1
  •  3
  •   Jacob    14 年前

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

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