美文网首页
7中两列定宽中间自适应三列布局

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

作者: Creator93 | 来源:发表于2018-03-27 22:17 被阅读0次
<!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>

相关文章

  • CSS布局

    一列布局 一列水平居中 一列垂直居中 两列布局 左定宽右自适应 左自适应右定宽 三列布局 左右定宽中间自适应 左右...

  • 前端常见布局方式

    常见的布局方式 常见的布局这么几种单列水平居中布局, 一列定宽一列自适应布局, 两列定宽一列自适应布局, 两侧定宽...

  • css布局

    左边定宽,右边宽度自适应 等高自适应,两列布局

  • 三栏布局:圣杯、双飞翼、flex、栅格

    --- 布局:圣杯、双飞翼、flex布局 三列布局,中间宽度自适应,两边定宽; 中间栏要在浏览器中优先展示渲染; ...

  • CSS:三栏布局

    -三列布局,中间宽度自适应,两边定宽; -中间栏要在浏览器中优先展示渲染; -允许任意列的高度最高; 1. 绝对定...

  • 关于你不可不知的“圣杯布局”

    圣杯布局格式要求: 1、三列布局,中间宽度自适应,两边定宽;2、中间栏要在浏览器中优先展示渲染;3、允许任意列的高...

  • 2018-03-19 css 实现左列定宽,右列自适应宽度,等高

    上次面试提到了一个css布局:实现左列定宽,右列自适应宽度,等高布局上次没有答出来,只实现了左列定宽,右列自适应宽...

  • HTML+CSS实现两栏和三栏布局

    三栏布局 三列自适应布局通常指两边定宽,中间部分宽度自适应。这里主要分为两大类,一类是基于position传统的实...

  • CSS布局

    圣杯布局:三列布局,中间宽度自适应,两边定宽;中间栏要在浏览器中优先展示渲染; 三个子元素设置为 float 中...

  • 圣杯布局

    圣杯布局 要求:三列布局;中间宽度自适应,两边内容定宽。 好处:重要的内容放在文档流前面可以优先渲染 原理:利用相...

网友评论

      本文标题:7中两列定宽中间自适应三列布局

      本文链接:https://www.haomeiwen.com/subject/jzlecftx.html