第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

假設(shè)高度已知,左右寬度固定,實(shí)現(xiàn)三欄布局的5種方法

標(biāo)簽:
Html/CSS Html5 CSS3

第一种方法 float

<style>
    *{
        padding:0;
        margin:0;
    }
    .big div{
        height:100px;
    }
    .big .left{
        width:300px;
        float:left;
        background:red;
    }
    .big .right{
        width:300px;
        float:right;
        background:yellow;
    }
    .big .center{
        background:blue;
    }
</style>

<div class="big">
    <div class="left">
       
    </div>
    <div class="right">
      
    </div>
    <div class="center">
        浮动解决方案
    </div>
</div>

图片描述
第一种解决方案基本上没有什么难度,平时应该也会用到很多!

第二种方法:absolute

<style>
 .position{
        margin-top:10px;
    }
    .position>div{
        position:absolute;
        height:100px;
    }
    .position .left{
        left:0;
        width:300px;
        background:red;
    }
     .position .right{
        right:0;
        width:300px;
        background:yellow;
    }
    .position .center{
        left:300px;
        right:300px;
        background:blue;
    }
</style>
<div class="position">
    <div class="left">
       
    </div>
    <div class="right">
      
    </div>
    <div class="center">
        绝对定位方案2
    </div>
</div>

图片描述

第二种方法也是轻松实现效果。

第三种方法:flexbox

<style>
 .flex{
        margin-top:120px;
        display:flex;
    }
    .flex>div{
        height:100px;
    }
    .flex .left{
        width:300px;
        background:red;
    }
    .flex .center{
        flex:1;
        background:blue;
    }
    .flex .right{
        width:300px;
        background:yellow;
    }
</style>

<div class="flex">
    <div class="left">
       
    </div>
    <div class="center">
        flex方案
    </div>
    <div class="right">
      
    </div>
</div>

图片描述

第四种方法:表格布局

<style>
.table{
        margin-top:10px;
        width:100%;
        display:table;
        height:100px;
    }
    .table>div{
        display:table-cell;
    }
     .table .left{
        width:300px;
        background:red;
    }
    .table .center{
        background:blue;
    }
    .table .right{
        width:300px;
        background:yellow;
    }
</style>


<div class="table">
    <div class="left">
       
    </div>
    <div class="center">
        table方案
    </div>
    <div class="right">
      
    </div>
</div>

图片描述
table方案同样实现,只是现在我们可能已经很少使用表格布局了。页面渲染性能也要差一点!

第五种方法:网格布局grid

<style>
  .grid{
        margin-top:10px;
        display:grid;
        width:100%;
        grid-template-rows:100px;
        grid-template-columns: 300px auto 300px;
    }
    .grid .left{
        background:red;
    }
    .grid .center{
        background:blue;
    }
    .grid .right{
        background:yellow;
    }
</style>

<body>
<div class="grid">
    <div class="left">
       
    </div>
    <div class="center">
        grid方案
    </div>
    <div class="right">
      
    </div>
</div>
</body>

图片描述
网格布局方法也实现了,CSS3的网格布局有点类似于bootstrap的栅格化布局,都是以网格的方式来划分元素所占的区块。

问题没有结束,我们继续讨论。五种解决方案哪一个更好呢?笔者一直认为技术没有好坏之分,完全取决于你用在什么地方。

个人认为五种方法的优缺点:

  1. 浮动:兼容性好,如果对兼容性有明确的要求使用浮动应该满足需求,但是一定要处理好与周边元素的关系,因为一不注意浮动就可能造成页面布局混乱等问题,不过解决浮动带来的副作用方法也不少这里我们不做讨论。

  2. 绝对定位:简单直接,但是会使父元素脱离正常文档流里面的子元素也会跟着脱离。

  3. flex:目前看来比较完美,不过现在稍微完美一点的技术都存在或多或少的兼容性问题,同样这个样式IE8下是不支持的!(IE呀!)

  4. 表格布局:表格布局虽然没有什么大的问题,但是在我们要细化结构的时候会显得很繁琐,同时表格布局三个单元格的高度会一起变动也不利于我们进行布局。

  5. 网格布局:代码优美简洁,不过还是兼容性问题。但是未来是美好的!

项目地址:github

點(diǎn)擊查看更多內(nèi)容
1人點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報(bào)

0/150
提交
取消