学习笔记(二)

三栏布局

方法一:float(记得清除浮动)

<section class="layout float">
    <style>
        .layout.float .left{
            float: left;
            width: 300px;
            background-color: red;
        }
        .layout.float .center{
            background-color: pink;
        }
        .layout.float .right{
            float: right;
            width: 300px;
            background-color: blue;
        }
    </style>
    <article class="left-center-right">
        <div class="left"></div>
        <div class="right"></div>
        <div class="center">
            <h2>第一种方法:float</h2>
        </div>
    </article>
</section>

方法二:absolute(不适合页面布局)

<section class="layout absolute">
    <style>
        .layout.absolute .left-center-right>div{
            position: absolute;
        }
        .layout.absolute .left{
            left: 0;
            width: 300px;
            background-color: blue;
        }
        .layout.absolute .center{
            left: 300px;
            right: 300px;
            background-color: pink;
        }
        .layout.absolute .right{
            right: 0;
            width: 300px;
            background-color: red;
        }
    </style>
    <article class="left-center-right">
        <div class="left"></div>
        <div class="center">
            <h2>第二种方法:absolute</h2>
        </div>
        <div class="right"></div>
    </article>
</section>

方法三:flex(布局强但存在IE兼容性问题)

<section class="layout flexbox">
    <style>
        .layout.flexbox{
            margin-top: 200px;
        }
        .layout.flexbox .left-center-right{
            display: flex;
        }
        .layout.flexbox .left{
            width: 300px;
            background-color: red;
        }
        .layout.flexbox .center{
            flex: 1;
            background-color: pink;
        }
        .layout.flexbox .right{
            width: 300px;
            background-color: blue;
        }
    </style>
    <article class="left-center-right">
        <div class="left"></div>
        <div class="center">
            <h2>第三种方法:flex</h2>
        </div>
        <div class="right"></div>
    </article>
</section>

方法四:表格布局(使用方便,不存在兼容问题)

<section class="layout table">
    <style>
        .layout.table .left-center-right{
            width: 100%;
            display: table;
            height: 100px;
        }
        .layout.table .left-center-right>div{
            display: table-cell;
        }
        .layout.table .left{
            width: 300px;
            background-color: blue;
        }
        .layout.table .center{
            background-color: pink;
        }
        .layout.table .right{
            width: 300px;
            background-color: red;
        }
    </style>
    <article class="left-center-right">
        <div class="left"></div>
        <div class="center">
            <h2>第四种方法:表格布局</h2>
        </div>
        <div class="right"></div>
    </article>
</section>

方法五:网格布局(布局强大,兼容性差)

<section class="layout grid">
    <style>
        .layout.grid .left-center-right{
            display: grid;
            width: 100%;
            grid-template-rows: 100px;
            grid-template-columns: 300px auto 300px;
        }
        .layout.grid .left{
            background-color: red;
        }
        .layout.grid .center{
            background-color: pink;
        }
        .layout.grid .right{
            background-color: blue;
        }
    </style>
    <article class="left-center-right">
        <div class="left"></div>
        <div class="center">
            <h2>第五种方法:网格布局</h2>
        </div>
        <div class="right"></div>
    </article>
</section>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值