CSS实现三栏布局的几种方案

该博客主要介绍的是通过css实现三栏布局的几种方案

通过浮动实现三栏布局

<section>
        <style type="text/css">
            .float-layout div{
                height: 100px;

            }
            .float-layout .left{
                float: left;
                width: 200px;
                background-color: red;
            }
            .float-layout .right{
                float: right;
                width: 200px;
                background-color: yellow;
            }
            .float-layout .center{
                margin:0 200px;
                background-color: blue;
            }
        </style>
        <article class="float-layout">
            <div class="left">1</div>
            <div class="right">3</div>
            <div class="center">float实现三栏布局解决方案</div>

        </article>
    </section>

通过定位实现三栏布局

<section>
        <style type="text/css">
                .position-layout div{
                    height: 100px;
                    margin-top: 20px;//是为了和上面的有一定的间距

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

                .position-layout .center{
                    margin: 0 200px;
                    margin-top: 20px;
                    background-color: blue;
                }
                .position-layout .right{
                    position: absolute;
                    top: 100px;
                    right:0px;
                    width: 200px;
                    background-color: yellow;
                }
        </style>
        <article class="position-layout">
            <div class="left">1</div>
            <div class="center">position实现三栏布局解决方案</div>
            <div class="right">3</div>
        </article>
    </section>

通过flex实现三栏布局

<section>
        <style type="text/css">
            .flex-layout{
                display: flex;
                height: 100px;
                margin-top: 20px;
            }
            .flex-layout .left{
                width: 200px;
                background-color: red;

            }
            .flex-layout .center{
                flex: 1;
                background-color: blue;
            }
            .flex-layout .right{
                width: 200px;
                background-color: yellow;
            }
        </style>
        <article class="flex-layout">
            <div class="left">1</div>
            <div class="center">flex实现三栏布局解决方案</div>
            <div class="right">3</div>
        </article>
    </section>

通过table实现三栏布局

<section>
        <style type="text/css">
            .table-layout{
                display: table;
                width: 100%;
                margin-top: 20px;
            }
            .table-layout>div{
                display: table-cell;
                height: 100px;

            }
            .table-layout .left{
                width: 200px;
                background-color: red;
            }
            .table-layout .right{
                width: 200px;
                background-color: yellow;
            }
            .table-layout .center{
                background-color: blue;
            }
        </style>
        <article class="table-layout">
            <div class="left">1</div>
            <div class="center">table实现三栏布局解决方案</div>
            <div class="right">3</div>
        </article>
    </section>

通过grid实现三栏布局

<section>
        <style type="text/css">
            .grid-layout{
                display: grid;
                grid-template-columns: 200px auto 200px;
                height: 100px;
                margin-top: 20px;   
            }
            .grid-layout .left{
                background-color: red;
            }
            .grid-layout .center{
                background-color: blue;
            }
            .grid-layout .right{
                background-color: yellow;
            }
        </style>
        <article class="grid-layout">
            <div class="left">1</div>
            <div class="center">grid实现三栏布局解决方案</div>
            <div class="right">3</div>
        </article>
    </section>

实例图片如下:
实例图片

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值