日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
css中有哪些實(shí)現(xiàn)等高布局常的方法-創(chuàng)新互聯(lián)

這篇文章給大家介紹css中有哪些實(shí)現(xiàn)等高布局常的方法,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。

創(chuàng)新互聯(lián)長(zhǎng)期為成百上千家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為雨花企業(yè)提供專業(yè)的成都做網(wǎng)站、網(wǎng)站制作,雨花網(wǎng)站改版等技術(shù)服務(wù)。擁有十多年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。

什么是css

css是一種用來表現(xiàn)HTML或XML等文件樣式的計(jì)算機(jī)語言,主要是用來設(shè)計(jì)網(wǎng)頁的樣式,使網(wǎng)頁更加美化。它也是一種定義樣式結(jié)構(gòu)如字體、顏色、位置等的語言,并且css樣式可以直接存儲(chǔ)于HTML網(wǎng)頁或者單獨(dú)的樣式單文件中,而樣式規(guī)則的優(yōu)先級(jí)由css根據(jù)這個(gè)層次結(jié)構(gòu)決定,從而實(shí)現(xiàn)級(jí)聯(lián)效果,發(fā)展至今,css不僅能裝飾網(wǎng)頁,也可以配合各種腳本對(duì)于網(wǎng)頁進(jìn)行格式化。

等高布局的方式

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

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

偽等高

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

真等高

子元素高度相等

先來看看偽等高實(shí)現(xiàn)方式

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

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

  • table

  • absoult

  • flex

  • grid

  • js

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

主要利用負(fù)margin來實(shí)現(xiàn), 具體 負(fù)margin實(shí)現(xiàn)可以參考下這篇文章

 
        

left

                     

我是中間部分的內(nèi)容

            

我是中間部分的內(nèi)容

            

我是中間部分的內(nèi)容

            

我是中間部分的內(nèi)容

        
        

right

        11111111111
    
.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布局

  
        

left

                     

我是中間部分的內(nèi)容

            

我是中間部分的內(nèi)容

            

我是中間部分的內(nèi)容

            

我是中間部分的內(nèi)容

        
        

right

        11111111111
    
.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


        

left

 
                     

我是中間部分的內(nèi)容

            

我是中間部分的內(nèi)容

            

我是中間部分的內(nèi)容

            

我是中間部分的內(nèi)容

        
        

right

    
   .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;
}

    

left

               

我是中間部分的內(nèi)容

        

我是中間部分的內(nèi)容

        

我是中間部分的內(nèi)容

        

我是中間部分的內(nèi)容

         

right

真實(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;
    }

    

left

               

我是中間部分的內(nèi)容

        

我是中間部分的內(nèi)容

        

我是中間部分的內(nèi)容

        

我是中間部分的內(nèi)容

         

right

真實(shí)等高之 - js

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

        

left

                       

我是中間部分的內(nèi)容

            

我是中間部分的內(nèi)容

            

我是中間部分的內(nèi)容

            

我是中間部分的內(nèi)容

                 

right

    
.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)等高布局常的方法就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。


新聞標(biāo)題:css中有哪些實(shí)現(xiàn)等高布局常的方法-創(chuàng)新互聯(lián)
網(wǎng)站網(wǎng)址:http://www.dlmjj.cn/article/ceohhs.html

其他資訊