三栏布局的5种方法

image.png
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!--SEO优化-->
    <meta name="Author" content="">
    <meta name="Keywords" content="">
    <meta name="Description" content="">

    <title>三栏布局</title>
    <style media="screen">
        html *{
            margin: 0px;
            padding: 0px;
        }

        .layout article div {
            min-height: 100px;
        }

        section {
            margin-top: 30px;
        }

    </style>
</head>
<body>
    <section class="float layout">
        <style media="screen">
            .float.layout .left {
                float: left;
                width: 300px;
                background: red;
            }

            .float.layout .right {
                float: right;
                width: 300px;
                background: blue;
            }

            .float.layout .center {
                background: orange;
            }
        </style>
        <article class="right-left-center">
            <div class="left"></div>
            <div class="right"></div>
            <div class="center">
                <h2>float浮动布局</h2>
            </div>
        </article>
    </section>

    <section class="position layout">
        <style>
            .position.layout .left {
                position: absolute;
                left: 0;
                width: 300px;
                background-color: red;
            }
            .position.layout .right {
                position: absolute;
                right: 0;
                width: 300px;
                background-color: blue;
            }
            .position.layout .center {
                position: absolute;
                right: 300px;
                left: 300px;
                background-color: orange;
            }
        </style>
        <article class="right-left-center">
            <div class="left"></div>
            <div class="right"></div>
            <div class="center">
                <h2>
                    position绝对定位
                </h2>
            </div>
        </article>
    </section>

    <section class="flexbox layout">
        <style>
            .flexbox.layout {
                margin-top: 160px;
            }
            .layout.flexbox .right-left-center {
                display: flex;
            }
            .layout.flexbox .left {
                width: 300px;
                background-color: red;
            }
            .layout.flexbox .right {
                width: 300px;
                background-color: blue;
            }
            .layout.flexbox .center {
                background-color: orange;
                flex: 1;
            }
        </style>
        <article class="right-left-center">
            <div class="left"></div>
            <div class="center">
                <h2>flexbox flex布局</h1>
            </div>
            <div class="right"></div>
        </article>
    </section>

    <section class="table-cell layout">
        <style>
            .table-cell.layout .right-left-center {
                display: table;
                height: 100px;
                width: 100%;
            }
            .table-cell.layout .right-left-center>div {
                display: table-cell;
            }
            .table-cell.layout .left {
                width: 300px;
                background: red;
            }
            .table-cell.layout .right {
                width: 300px;
                background: blue;
            }
            .table-cell.layout .center {
                background: orange;
            }

        </style>
        <article class="right-left-center">
            <div class="left"></div>
            <div class="center">
                <h2>table 表格布局</h2>
            </div>
            <div class="right"></div>
        </article>
    </section>

    <section class="layout grid">
        <style>
            .layout.grid .right-left-center {
                display: grid;
                width: 100%;
                grid-template-rows: 100px;
                grid-template-columns: 300px auto 300px;
            }
            .layout.grid .left {
                background: red;
            }
            .layout.grid .center {
                background: orange;
            }
            .layout.grid .right {
                background: blue;
            }
        </style>
        <article class="right-left-center">
            <div class="left"></div>
            <div class="center">
                <h2>grid 网格布局</h2>
            </div>
            <div class="right"></div>
        </article>
    </section>
</body>
</html>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容