当内容不满1屏时, 使footer固定在底部的方法

最初发表于: 2019-11-18 18:09:48

示例代码如下

<!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>
        html,
        body {
            height: 100%;
            margin: 0;
            padding: 0;
        }

        .page {
            box-sizing: border-box;
            min-height: 100%;
            padding-bottom: 62px;
        }

        footer {
            margin-top: -62px;
            height: 62px;
            line-height: 62px;
            background: #000;
            color: #fff;
        }

       /* 重点在于上面3个样式中的部分 */

        header {
            background: #f0f0f0;
            height: 40px;
        }
    </style>
</head>

<body>
    <div class="page">
        <header>
            This is Header.
        </header>
        <div class="content">
            Write content here.
        </div>
    </div>
    <footer>
        This is Footer.
    </footer>

</body>

</html>