如何实现两栏布局、三栏布局

1. 两栏布局,左边定宽

	<div id="left">左边定宽</div>
    <div id="right">右边自适应</div>

第一种:


	#left {
        float: left;
        width: 200px;
        margin-right: -200px;
        height: 50%;
        background: green;
    }

    #right {
        float: left;
        margin-left: 210px;
        width: 100%;
        height: 50%;
        background: red;
    }

在这里插入图片描述

第二种:


    #left {
        width: 200px;
        height: 50%;
        position: absolute;
        background: red;
    }

    #right {
        height: 50%;
        width: 100%;
        margin-left: 200px;
        background: yellow;
    }

在这里插入图片描述

第三种:


    #left {
        width: 200px;
        background: red;
        float: left;
        height: 50%;
    }

    #right {
        width: 100%;
        margin-left: 210px;
        background: pink;
        height: 50%;
    }

在这里插入图片描述

1. 三栏布局,中间自适应

	<div class="container">
        <div class="middle">
            中间
        </div>
        <div class="left">
            左侧
        </div>
        <div class="right">
            右侧
        </div>
    </div>
    <div class="footer">
        尾部
    </div>
第1种:圣杯布局
    .container {
        padding: 0 220px 0 220px;
        overflow: hidden;
    }

    .left,
    .middle,
    .right {
        position: relative;
        float: left;
        // 多列等高
        margin-bottom: -2000px;
        padding-bottom: 2000px;
    }

    .left {
        margin-left: -100%;
        left: -200px;
        width: 200px;
        background: red;
    }

    .right {
        margin-left: -220px;
        right: -220px;
        width: 220px;
        background: green;
    }

    .middle {
        width: 100%;
        background: blue;
    }

在这里插入图片描述

第2种:通过positon定位实现三栏布局中间自适应
	.container {
        position: relative;
    }

    .left {
        width: 200px;
        background-color: blue;
        position: absolute;
        left: 0;
        top: 0;
    }

    .right {
        width: 200px;
        background-color: rgb(197, 21, 74);
        position: absolute;
        right: 0;
        top: 0;
    }

    .middle {
        background-color: rgb(48, 201, 1);
        margin-left: 200px;
        margin-right: 200px;
    }

在这里插入图片描述

第3种:浮动法
	.left {
        background-color: rgb(33, 36, 204);
        width: 200px;
        float: left;
    }

    .right {
        background-color: rgb(25, 179, 206);
        width: 200px;
        float: right;
    }

    .middle {
        background-color: rgb(48, 201, 1);
        margin-left: 200px;
        margin-right: 200px;
    }

在这里插入图片描述

第4种:margin负值法(双飞翼)
    <div id="main">
        <div class="content">1</div>
    </div>
    <div id="left">1</div>
    <div id="right">1</div>
#main {
        float: left;
        width: 100%;
    }

    .content {
        margin: 0 200px;
        height: 100%;
        background: red;
    }

    #left {
        float: left;
        width: 200px;
        margin-left: -100%;
        background: blue;
    }

    #right {
        float: left;
        width: 200px;
        margin-left: -200px;
        background: green;
    }

margin负值法(双飞翼)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值