7中两列定宽中间自适应三列布局

<!DOCTYPE html>
<html>
<head>
    <title>两列定宽中间自适应布局</title>
    <meta charset="utf-8">
</head>
<body>
<h1>1、流体布局</h1>

<div class="left"></div>
<div class="right"></div>
<div class="center"></div>

<style type="text/css">

    .left{
        width: 200px;
        height: 100px;
        background-color: red;
        float: left;

    }
    .right{
        width: 100px;
        height: 100px;
        background-color: green;
        float: right;
    }
    .center{
        height: 100px;
        background-color: yellow;
        margin-left: 200px;
        margin-right: 100px;
    }
</style>
<h1>2、BFC三栏布局</h1>
<p>BFC规则,BFC区域不会与浮动元素重叠,利用这一点进行三列布局</p>
<p>
    触发条件:
        1、body 根元素
        2、浮动元素:float 除 none 以外的值
        3、绝对定位元素:position (absolute、fixed)
        4、display 为 inline-block、table-cells、flex
        5、overflow 除了 visible 以外的值 (hidden、auto、scroll)
</p>
<div class="BFCleft"></div>
<div class="BFCright"></div>
<div class="BFCcenter"></div>
<style type="text/css">
    .BFCleft{
        width: 300px;
        height: 200px;
        background-color: blue;
        float: left;
        margin-right: 10px;

    }
    .BFCright{
        width: 300px;
        height: 200px;
        float: right;
        background-color: yellow;
        margin-left: 10px;
    }
    .BFCcenter{
        height: 200px;
        background-color: green;
        overflow: hidden;
    }
</style>
<h1>3、双飞翼布局SFY</h1>
<p>利用的是浮动元素 margin 负值的应用</p>
<div class="container">
    <div class="SFYcenter"></div>
</div>
<div class="SFYleft"></div>
<div class="SFYright"></div>
<style type="text/css">
    .container{
        width: 100%;
        float: left;
    }
    .SFYcenter{
        height: 100px;
        background-color: red;
        margin-left: 210px;
        margin-right: 110px;
    }
    .SFYleft{
        float: left;
        width: 200px;
        height: 100px;
        background-color: green;
        margin-left: -100%;

    }
    .SFYright{
        float: right;
        width: 100px;
        height: 100px;
        background-color: blue;
        margin-left: -200px;
    }
</style>
<h1>4、圣杯布局SB</h1>
<p>圣杯布局有包裹div且全部左浮动</p>
<div class="wrap">
    <div class="SBcenter"></div>
    <div class="SBleft"></div>
    <div class="SBright"></div>
</div>
<style type="text/css">
    .wrap{
        margin-left: 120px;
        margin-right: 220px;
    }
    .SBcenter{
        float: left;
        height: 100px;
        background-color: blue;
        width: 100%;/*才会展示出来*/
    }
    .SBleft{
        float: left;
        width: 100px;
        height: 100px;
        background-color: yellow;
        margin-left: -100%;
        position: relative;
        left: -120px;

    }
    .SBright{
        float: left;
        width: 200px;
        height: 100px;
        background-color: red;
        margin-left: -200px;
        position: relative;
        right: -220px;
        
    }
</style>
<div style="clear: both;"></div>
<h1>5、Flex布局</h1>
<div class="FlexWrap">
    <div class="Flexcenter"></div>
    <div class="Flexleft"></div>
    <div class="Flexright"></div>
</div>
<style type="text/css">
    .FlexWrap{
        display: flex;
    }
    .Flexcenter{
        flex-grow: 1;
        height: 100px;
        background-color: blue;
    }
    .Flexleft{
        order: -1;
        flex: 0 1 200px;
        background-color: red;
        height: 100px;
        margin-right: 10px;

    }
    .Flexright{
        flex: 0 1 100px;
        background-color: green;
        height: 100px;
        margin-left: 10px;
    }
</style>
<h1>6、绝对定位布局position: absolute</h1>
<div class="PAWrap">
    <div class="PAcenter"></div>
    <div class="PAleft"></div>
    <div class="PAright"></div>
</div>
<style type="text/css">
    .PAWrap{
        position: relative;
    }
    .PAcenter{
        height: 200px;
        margin: 0 160px 0 210px;
        background-color: red;
    }
    .PAleft{
        width: 200px;
        height: 200px;
        background-color: yellow;
        position: absolute;
        left: 0;
        top: 0;
    }
    .PAright{
        width: 150px;
        height: 200px;
        background-color: green;
        position: absolute;
        top: 0;
        right: 0;
    }
</style>

<h3>7、table布局</h3>
<div id="tablewrap">
   <div id="left_table"></div>
    <div id="tablexmain"></div>
   <div id="right_table"></div>
</div>
<style type="text/css">
   #tablewrap{
    display: table;
    width:100%;
   }
   #tablemain,#left_table,#right_table{
    display: table-cell;
   }
   #tablexmain{
     background-color: blue;
     height: 300px;
   }
   #left_table{
    height: 300px;
    width: 200px;
    background-color: red;
   }
   #right_table{
    height: 300px;
    width: 100px;
    background-color: green;
   }
   /*缺点无法设置栏间距*/
</style>
</body>
 
</html>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 和上面的解决方案是一样的,自己动脑筋哦下面的overflow的方式display:table和flex大家自己练习。
    奶瓶SAMA阅读 2,286评论 0 0
  • 大家好,今天是2016年里的最后一天。 此刻的你是否会对即将逝去的一年感到不舍?或者深叹口气觉得终于熬过了这一年?...
    遇见卡米拉阅读 1,339评论 0 0
  • 拉萨到西宁22小时,四个人的软卧包间,火车盒饭不好吃,最不能忍受的还是厕所。 西宁火车站等出租车,几分钟来一辆,半...
    石默燃阅读 1,248评论 0 0
  • 一,我不知道我是谁 人生只要有裂缝,阳光才能照进来…… “行啦!别说话啦!烦不烦!安静会儿!”一天了,不知道为什么...
    雪羽天使阅读 2,463评论 0 1
  • 01 上大学时,认识一个“有趣”的女生。她几乎每周都有饭局,和校外同学一起玩滑板,参加户外音乐节,追星,和酷炫的男...
    欣所向之阅读 4,449评论 4 22