css有什么方式可以實(shí)現(xiàn)等高布局-創(chuàng)新互聯(lián)

css有什么方式可以實(shí)現(xiàn)等高布局?首先我們得知道什么是等高布局?小編給大家總結(jié)了以下內(nèi)容,一起往下看吧。

創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比賀州網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式賀州網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋賀州地區(qū)。費(fèi)用合理售后完善,10多年實(shí)體公司更值得信賴。

css有什么方式可以實(shí)現(xiàn)等高布局

指在同一個(gè)父容器中,子元素高度相等的布局。

從等高布局實(shí)現(xiàn)方式來說分為兩類:

1、偽等高

子元素高度差依然存在,只是視覺上給人感覺就是等高。

2、真等高

子元素高度相等。

偽等高實(shí)現(xiàn)方式:

通過負(fù)margin和Padding實(shí)現(xiàn)

真等高實(shí)現(xiàn)方式:

1、table

2、absoult

3、flex

4、grid

5、js

偽等高之-負(fù)margin和padding

主要利用負(fù)margin來實(shí)現(xiàn),如下:

 <div class="layout parent">
        <div class="left"><p>left</p></div>
        <div class="center">
            <p>我是中間部分的內(nèi)容</p>
            <p>我是中間部分的內(nèi)容</p>
            <p>我是中間部分的內(nèi)容</p>
            <p>我是中間部分的內(nèi)容</p>
        </div>
        <div class="right"><p>right</p></div>
        <div style="clear: both;">11111111111</div>
    </div>
.parent{
    position: relative;
    overflow:hidden;
    color: #efefef;
}
.center,
.left,
.right {
    box-sizing: border-box;
    float: left;
}
.center {
    background-color: #2ECC71;
    width: 60%;
}

.left {
    width: 20%;
    background-color: #1ABC9C;
}
.right {
    width: 20%;
    background-color: #3498DB;
}
.left,
.right,
.center  {
    margin-bottom: -99999px;
    padding-bottom: 99999px;
}

真實(shí)等高之 - table布局

  <div class="layout parent">
        <div class="left"><p>left</p></div>
        <div class="center">
            <p>我是中間部分的內(nèi)容</p>
            <p>我是中間部分的內(nèi)容</p>
            <p>我是中間部分的內(nèi)容</p>
            <p>我是中間部分的內(nèi)容</p>
        </div>
        <div class="right"><p>right</p></div>
        <div style="clear: both;">11111111111</div>
    </div>
    .parent{
        position: relative;
        display: table;
        color: #efefef;
    }
    .center,
    .left,
    .right {
        box-sizing: border-box;
        display: table-cell
    }
    .center {
        background-color: #2ECC71;
        width: 60%;
    }

    .left {
        width: 20%;
        background-color: #1ABC9C;
    }
    .right {
        width: 20%;
        background-color: #3498DB;
    }

真實(shí)等高之 - absolute

    <div class="layout parent">
        <div class="left"><p>left</p> </div>
        <div class="center">
            <p>我是中間部分的內(nèi)容</p>
            <p>我是中間部分的內(nèi)容</p>
            <p>我是中間部分的內(nèi)容</p>
            <p>我是中間部分的內(nèi)容</p>
        </div>
        <div class="right"><p>right</p></div>
    </div>
   .parent{
        position: absolute;
        color: #efefef;
        width:100%;
        height: 200px;
    }

    .left,
    .right,
    .center {
        position: absolute;
        box-sizing: border-box;
        top:0;
        bottom:0;
    }
    .center {
        background-color: #2ECC71;
        left: 200px;
        right: 300px;
    }

    .left {
        width: 200px;
        background-color: #1ABC9C;
    }
    .right {
        right:0;
        width: 300px;
        background-color: #3498DB;
    }

真實(shí)等高之 - flex

.parent{
    display: flex;
    color: #efefef;
    width:100%;
    height: 200px;
}

.left,
.right,
.center {
    box-sizing: border-box;
    flex: 1;
}
.center {
    background-color: #2ECC71;
}
.left {
    background-color: #1ABC9C;
}
.right {
    background-color: #3498DB;
}
<div class="layout parent">
    <div class="left"><p>left</p> </div>
    <div class="center">
        <p>我是中間部分的內(nèi)容</p>
        <p>我是中間部分的內(nèi)容</p>
        <p>我是中間部分的內(nèi)容</p>
        <p>我是中間部分的內(nèi)容</p>
    </div>
    <div class="right"><p>right</p></div>
</div>

真實(shí)等高之 - grid

    .parent{
        display: grid;
        color: #efefef;
        width:100%;
        height: 200px;
        grid-template-columns: 1fr 1fr 1fr;
    }

    .left,
    .right,
    .center {
        box-sizing: border-box;
    }
    .center {
        background-color: #2ECC71;
    }
    .left {
        background-color: #1ABC9C;
    }
    .right {
        background-color: #3498DB;
    }
<div class="layout parent">
    <div class="left"><p>left</p> </div>
    <div class="center">
        <p>我是中間部分的內(nèi)容</p>
        <p>我是中間部分的內(nèi)容</p>
        <p>我是中間部分的內(nèi)容</p>
        <p>我是中間部分的內(nèi)容</p>
    </div>
    <div class="right"><p>right</p></div>
</div>

真實(shí)等高之 - js

獲取所有元素中最高列,然后再去比對(duì)再進(jìn)行修改

    <div class="layout parent">
        <div class="left"><p>left</p> </div>
        <div class="center">
            <p>我是中間部分的內(nèi)容</p>
            <p>我是中間部分的內(nèi)容</p>
            <p>我是中間部分的內(nèi)容</p>
            <p>我是中間部分的內(nèi)容</p>
        </div>
        <div class="right"><p>right</p></div>
    </div>
    .parent{
        overflow: auto;
        color: #efefef;
    }
    .left,
    .right,
    .center {
        float: left;
    }
    .center {
        width: 60%;
        background-color: #2ECC71;
    }
    .left {
        width: 20%;
        background-color: #1ABC9C;
    }
    .right {
        width: 20%;
        background-color: #3498DB;
    }
     // 獲取最高元素的高度
    var nodeList = document.querySelectorAll(".parent > div");
    var arr = [].slice.call(nodeList,0);
    var maxHeight = arr.map(function(item){
        return item.offsetHeight
    }).sort(function(a, b){
        return a - b;
    }).pop();
    arr.map(function(item){
        if(item.offsetHeight < maxHeight) {
            item.style.height = maxHeight + "px";
        }
    });

如圖:

css有什么方式可以實(shí)現(xiàn)等高布局

關(guān)于css有什么方式可以實(shí)現(xiàn)等高布局就分享到這里了,當(dāng)然并不止以上和大家分析的辦法,不過小編可以保證其準(zhǔn)確性是絕對(duì)沒問題的。希望以上內(nèi)容可以對(duì)大家有一定的參考價(jià)值,可以學(xué)以致用。如果喜歡本篇文章,不妨把它分享出去讓更多的人看到。

網(wǎng)站欄目:css有什么方式可以實(shí)現(xiàn)等高布局-創(chuàng)新互聯(lián)
URL網(wǎng)址:http://www.muchs.cn/article42/pidec.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、網(wǎng)頁設(shè)計(jì)公司、動(dòng)態(tài)網(wǎng)站、靜態(tài)網(wǎng)站、品牌網(wǎng)站設(shè)計(jì)手機(jī)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)