想让div填满页面剩余空间,最简易的方式还是靠提前的布局。

这里提供两种方法:

(1)利用 height 样式的%比例设置布局

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        *{
            padding: 0px;
            margin: 0px;
        }
        html,body,#page{
            height: 100%; 
            width: 100%;
        }
    </style>
</head>
<body>
    <div >
        <div style="height: 20%; background:silver"></div>
        <div style="height: 80%; background:gray"></div>
    </div>
</body>
</html>

  

(2)利用 table

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <style>
            *{
                padding: 0px;
                margin: 0px;
            }
            html,body,#page{
                height: 100%; 
                width: 100%;
            }
            #tdcontent {
                height: 100%;
                background: silver;
            }
            #content {
                overflow: auto; /* or overflow: hidden; */
            }
        </style>
    </head>
    <body>
        <table >
            <tr>
                <td >
                    <div >header</div>
                </td>
            </tr>
            <tr>
                <td >
                    <div >content</div>
                </td>
            </tr>
        </table>
    </body>
</html>

(3)利用绝对定位,算出上面元素的height,将top属性设为该值,并设置bottom为0。

相关文章:

  • 2021-11-29
  • 2022-12-23
  • 2021-09-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-13
  • 2022-12-23
  • 2021-07-02
  • 2022-01-09
  • 2021-05-19
  • 2021-12-20
相关资源
相似解决方案