成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

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

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

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

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

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

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

1、偽等高

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

2、真等高

子元素高度相等。

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

通過負margin和Padding實現(xiàn)

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

1、table

2、absoult

3、flex

4、grid

5、js

偽等高之-負margin和padding

主要利用負margin來實現(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;
}

真實等高之 - 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;
    }

真實等高之 - 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;
    }

真實等高之 - 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>

真實等高之 - 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>

真實等高之 - js

獲取所有元素中最高列,然后再去比對再進行修改

    <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有什么方式可以實現(xiàn)等高布局

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

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

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

廣告

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

成都定制網(wǎng)站建設(shè)
西乌珠穆沁旗| 永昌县| 柳林县| 五寨县| 墨竹工卡县| 金溪县| 白玉县| 双牌县| 双牌县| 五大连池市| 巨野县| 郎溪县| 汪清县| 密山市| 绥中县| 南岸区| 怀宁县| 崇礼县| 德安县| 当雄县| 农安县| 惠水县| 铜山县| 吉隆县| 丰镇市| 闸北区| 舟山市| 咸丰县| 祁阳县| 盐源县| 治县。| 平原县| 丹棱县| 拉萨市| 平果县| 灵山县| 栾川县| 沛县| 呼图壁县| 五台县| 九寨沟县|