栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > Html/CSS > CSS教程

CSS 三栏布局方法归纳

CSS教程 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

CSS 三栏布局方法归纳

中间自适应,两边固定

1.用margin和float实现

css:


    * {
 margin: 0;
 padding: 0;
 text-align: center;
    }
    .left {
 float: left;
 width: 100px;
 background: yellow;
    }
    .right {
 float: right;
 width: 100px;
 background: green;
    }
    .center {
 margin: 0 100px;
 background: #ccc;
    }

html

    left
    right
    center
2.用float,margin负值实现

css


    * {
 margin: 0;
 padding: 0;
 text-align: center;
    }
    .left, .right, .center {
 float: left;
    }
    .left {
 width: 100px;
 margin-left: -100%;
 background: yellow;
    }
    .right {
 width: 100px;
 margin-left: -100px;
 background: green;
    }
    .center {
 width: 100%;
 background: #ccc;
    }

html

    center
    left
    right
3.用flex实现

css


    * {
 margin: 0;
 padding: 0;
 text-align: center;
    }
    .container {
 display: flex;
    }
    .left {
 width: 100px;
 background: yellow;
    }
    .right {
 width: 100px;
 background: green;
    }
    .center {
 flex: 1;
 background: #ccc;
    }

html

    left
    center
    right
中间固定,两边自适应

1. 用margin和float实现

css


    * {
 margin: 0;
 padding: 0;
 text-align: center;
    }
    .container {
 padding: 0 100px;
    }
    .left {
 float: left;
 width: 50%;
 margin-left: -100px;
 background: yellow;
    }
    .right {
 float: right;
 width: 50%;
 margin-right: -100px;
 background: green;
    }
    .center {
 float: left;
 width: 200px;
 background: #ccc;
    }

html

    left
    center
    right
2. 用flex实现

css


    * {
 margin: 0;
 padding: 0;
 text-align: center;
    }
    .container {
 display: flex;
    }
    .left {
 flex: 1;
 background: yellow;
    }
    .right {
 flex: 1;
 background: green;
    }
    .center {
 width: 200px;
 background: #ccc;
    }

html

    left
    center
    right
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/243038.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号