layout常用布局

120 阅读2分钟

1.浮动解决方案

2.绝对定位解决方案

3.flexbox解决方案

4.表格布局解决方案

5.网格布局解决方案

layout布局

  <!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>
        * {
            margin: 0;
            padding: 0;
        }

        .layout {
            min-width: 600px;
        }

        .layout article div {
            min-height: 100px;
        }
    </style>
</head>

<body>
    <!-- 浮动解决方案 -->
    <section class="layout float">
        <style>
            .layout.float .left {
                width: 300px;
                float: left;
                background-color: red;
            }

            .layout.float .center {
                background-color: yellow;
            }

            .layout.float .right {
                width: 300px;
                float: right;
                background-color: blue;
            }
        </style>
        <h1>浮动解决方案</h1>
        <article>
            <div class="left"></div>
            <div class="right"></div>
            <div class="center">
                <h2>浮动解决方案</h2>
                1.这是三栏布局的浮动解决方案;
                2.这是三栏布局的浮动解决方案;
                3.这是三栏布局的浮动解决方案;
                4.这是三栏布局的浮动解决方案;
                5.这是三栏布局的浮动解决方案;
                6.这是三栏布局的浮动解决方案;
            </div>
        </article>
    </section>
    <!-- 绝对定位解决方案 -->
    <section class="layout absolute">
        <style>
            .layout.absolute div {
                position: absolute;
            }

            .layout.absolute .left {
                left: 0;
                width: 300px;
                background-color: red;
            }

            .layout.absolute .center {
                left: 300px;
                right: 300px;
                background-color: yellow;
            }

            .layout.absolute .right {
                right: 0;
                width: 300px;
                background-color: blue;
            }
        </style>
        <h1>绝对定位解决方案</h1>
        <article>
            <div class="left"></div>
            <div class="center">
                <h2>绝对定位解决方案</h2>
                1.这是三栏布局的绝对定位解决方案;
                2.这是三栏布局的绝对定位解决方案;
                3.这是三栏布局的绝对定位解决方案;
                4.这是三栏布局的绝对定位解决方案;
                5.这是三栏布局的绝对定位解决方案;
                6.这是三栏布局的绝对定位解决方案;
            </div>
            <div class="right"></div>
        </article>
    </section>
    <div style="clear: both;"></div>
    <!-- flexbox解决方案 -->
    <section class="layout flexbox">
        <style>
            .layout.flexbox {
                margin-top: 110px;
            }

            .layout.flexbox .left-center-right {
                display: flex;
            }

            .layout.flexbox .left {
                width: 300px;
                background-color: red;
            }

            .layout.flexbox .center {
                flex: 1;
                background-color: yellow;
            }

            .layout.flexbox .right {
                width: 300px;
                background-color: blue;
            }
        </style>
        <h1>flexbox解决方案</h1>
        <article class="left-center-right">
            <div class="left"></div>
            <div class="center">
                <h2>flexbox解决方案</h2>
                1.这是三栏布局的flexbox解决方案;
                2.这是三栏布局的flexbox解决方案;
                3.这是三栏布局的flexbox解决方案;
                4.这是三栏布局的flexbox解决方案;
                5.这是三栏布局的flexbox解决方案;
                6.这是三栏布局的flexbox解决方案;
            </div>
            <div class="right"></div>
        </article>
    </section>
    <!-- 表格布局解决方案 -->
    <section class="layout table">
        <style>
            .layout.table .left-center-right {
                width: 100%;
                height: 100px;
                display: table;
            }

            .layout.table .left-center-right div {
                display: table-cell;
            }

            .layout.table .left {
                width: 300px;
                background: red;
            }

            .layout.table .center {
                background: yellow;
            }

            .layout.table .right {
                width: 300px;
                background: blue;
            }
        </style>
        <h1>表格布局解决方案</h1>
        <article class="left-center-right">
            <div class="left"></div>
            <div class="center">
                <h2>表格布局解决方案</h2>
                1.这是三栏布局的表格布局解决方案;
                2.这是三栏布局的表格布局解决方案;
                3.这是三栏布局的表格布局解决方案;
                4.这是三栏布局的表格布局解决方案;
                5.这是三栏布局的表格布局解决方案;
                6.这是三栏布局的表格布局解决方案;
            </div>
            <div class="right"></div>
        </article>
    </section>
    <!-- 网格布局解决方案 -->
    <section class="layout grid">
        <style>
            .layout.grid .left-center-right {
                width: 100%;
                display: grid;
                grid-template-rows: 100px;
                grid-template-columns: 300px auto 300px;
            }

            .layout.grid .left {
                background: red;
            }

            .layout.grid .center {
                background: yellow;
            }

            .layout.grid .right {
                background: blue;
            }
        </style>
        <h1>网格布局解决方案</h1>
        <article class="left-center-right">
            <div class="left"></div>
            <div class="center">
                <h2>网格布局解决方案</h2>
                1.这是三栏布局的网格布局解决方案;
                2.这是三栏布局的网格布局解决方案;
                3.这是三栏布局的网格布局解决方案;
                4.这是三栏布局的网格布局解决方案;
                5.这是三栏布局的网格布局解决方案;
                6.这是三栏布局的网格布局解决方案;
            </div>
            <div class="right"></div>
        </article>
    </section>
</body>

</html>