flex和圣杯布局

194 阅读1分钟

实现过程:

<!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>
        .HolyGrail{
            display: flex;
            min-height: 100vh;
            flex-direction: column;
        }
        header,footer{
            flex: 1;
            background-color: blue;
        }
        .HolyGrail-body{
            display: flex;
            flex: 1;
            
        }
        .HolyGrail-content{
            flex: 1;
            background-color: red;
        }
        .HolyGrail-nav,.HolyGrail-ads{
            flex: 0 0 12em;
            background-color: green;
        }
        .HolyGrail-nav{
            order: -1;
        }
    </style>
</head>
<body class="HolyGrail">
    <header>#header</header>
    <div class="HolyGrail-body">
        <main class="HolyGrail-content">content</main>
        <nav class="HolyGrail-nav">nav</nav>
        <main class="HolyGrail-ads">ads</main>
    </div>
    <footer>#footer</footer>
</body>
</html>

参考文章:

阮一峰老师文章