五种实现左中右自适应布局方法

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>五种实现左中右自适应布局方法</title>
    </head>
    <style type="text/css">
        /* 方法一 浮动 */
        /* .parent {
            clear: both;
        }
        .left{
            float: left;
            width: 200px;
            background-color: #0000FF;
        }
        .right{
            float: right;
            width: 200px;
            background-color: aqua;
        }
        .center{
            padding: 0 200px; //margin  也行
            background-color: aquamarine;
        } */
        /* 方法二 flex */
        /* .parent {
            display: flex;
        }
        .left{
            width: 200px;
            background-color: #0000FF;
        }
        .right{
            width: 200px;
            background-color: aqua;
        }
        .center{
            flex: 1;
            background-color: aquamarine;
        } */
        /* 方法三 定位*/
        /* .parent{
            position: relative;
        }
        .left{
            position: absolute;
            top: 0;
            left: 0;
        width: 200px;
            background-color: #0000FF;
        }
        .right{
            position: absolute;
            top: 0;
            right: 0;
            width: 200px;
            background-color: aqua;
        }
        .center{
            padding: 0 200px;
            background-color: aquamarine;
        } */
        /* 方法四 grid */
        /* .parent {
            display: grid;
            grid-template-columns: 200px auto 200px;
        }

        .left {
            background-color: #0000FF;
        }

        .right {
            background-color: aqua;
        }

        .center {
            background-color: aquamarine;
        } */
        /* 方法五 inline-block + calc */
        *{
            padding: 0;
            margin: 0;
        }
        .parent {
            clear: both;
            /* 干掉间隙 */
            font-size: 0
        }

        .left {
            display: inline-block;
            width: 200px;
            font-size: 16px;
            background-color: #0000FF;
        }

        .right {
            display: inline-block;
            width: 200px;
            font-size: 16px;
            background-color: aqua;
        }

        .center {
            display: inline-block;
            width: calc(100% - 400px);
            font-size: 16px;
            background-color: aquamarine;
        }
    </style>
    <body>
        <!-- 方法一 -->
        <!-- <div class="parent">
            <div class="left">
                左
            </div>
            <div class="right">
                右
            </div>
            <div class="center">
                中
            </div>
        </div> -->
        <!-- 方法二 -->
        <!-- <div class="parent">
            <div class="left">
                左
            </div>            
            <div class="center">
                中
            </div>
            <div class="right">
                右
            </div>
        </div> -->
        <!-- 方法三 -->
        <!-- <div class="parent">
            <div class="left">
                左
            </div>            
            <div class="center">
                中
            </div>
            <div class="right">
                右
            </div>
        </div> -->
        <!-- 方法四 -->
        <!-- <div class="parent">
            <div class="left">
                左
            </div>
            <div class="center">
                中
            </div>
            <div class="right">
                右
            </div>
        </div> -->
        <!-- 方法五 -->
        <div class="parent">
            <div class="left"></div>
            <div class="center"></div>
            <div class="right"></div>
        </div>
    </body>
</html>

 

转载于:https://www.cnblogs.com/mengfangui/p/10120021.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值