css實(shí)現(xiàn)上下固定中間自適應(yīng)布局

html:

<div class="top-center-bottom">
        <div class="top"></div>
        <div class="center"></div>
        <div class="bottom"></div>
</div>

1:使用定位實(shí)現(xiàn):

css:

.top-center-bottom>div{
  position:absolute;
}
.top-center-bottom .top{
  top:0;
  height:100px;
  width:100%;
  background:red;
}
.top-center-bottom .bottom{
  bottom:0;
  height:100px;
  width:100%;
  background:red;
}
.top-center-bottom .center{
  bottom:100px;
  top:100px;
  width:100%;
  background:green;
}

2:使用flexbox:

css:

 html, body, .top-center-bottom{
  height:100%;
}
.top-center-bottom{
   display:flex;
   flex-direction:column;
}
.top-center-bottom .top{
  height:100px;
  background:red;
}
 .top-center-bottom .bottom{
  height:100px;
  background:red;
  }
 .top-center-bottom .center{
 flex:1;
  background:green;
}

3:使用grid

css:

.html, body, .top-center-bottom{
  width:100%;
  height:100%;
}
.top-center-bottom{
  display:grid;
  grid-template-rows:100px auto 100px;
  grid-template-columns:100%
}
.top-center-top{
  background:red;
}
top-center-bottom{
  background:red;
}
top-center-center{
  background:green;
}

4:使用css table布局

html:

<div class="top-center-bottom">
        <div class="top"><div></div></div>
        <div class="center"><div></div></div>
        <div class="bottom"><div></div></div>
</div>

css:

html,body, .top-center-bottom{
        height:100%;
        width: 100%;
    } 
    .top-center-bottom{
        display:table;
    }
    .top-center-bottom>div{
        display: table-row;
    }
    .top-center-bottom .top{
        height: 100px;
        background: red;
    }
    .top-center-bottom .bottom{
        height: 100px;
        background: red;
    }
    .top-center-bottom .center{
        background: green;
    } 
注意:
<div class="top">里邊一定要有內(nèi)容,因?yàn)閐isplay: table-row;相當(dāng)于<div class="top">轉(zhuǎn)換為了<tr>標(biāo)簽,所以tr標(biāo)簽里是需要有內(nèi)容的
參考:
![Paste_Image.png](http://upload-images.jianshu.io/upload_images/6519824-213c5911dac658db.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 問(wèn)答題47 /72 常見(jiàn)瀏覽器兼容性問(wèn)題與解決方案? 參考答案 (1)瀏覽器兼容問(wèn)題一:不同瀏覽器的標(biāo)簽?zāi)J(rèn)的外補(bǔ)...
    _Yfling閱讀 14,150評(píng)論 1 92
  • 簡(jiǎn)介 CSS Grid布局 (又名"網(wǎng)格"),是一個(gè)基于二維網(wǎng)格布局的系統(tǒng),旨在改變我們基于網(wǎng)格設(shè)計(jì)的用戶界面方式...
    咕咚咚bells閱讀 2,700評(píng)論 0 4
  • 前言 溫馨提示:本文較長(zhǎng),圖片較多,本來(lái)是想寫一篇 CSS 布局方式的,但是奈何 CSS 布局方式種類太多并且實(shí)現(xiàn)...
    sunshine小小倩閱讀 3,266評(píng)論 0 59
  • 一:在制作一個(gè)Web應(yīng)用或Web站點(diǎn)的過(guò)程中,你是如何考慮他的UI、安全性、高性能、SEO、可維護(hù)性以及技術(shù)因素的...
    Arno_z閱讀 1,365評(píng)論 0 1
  • 張東輝,焦點(diǎn)初級(jí)43期堅(jiān)持原創(chuàng)分享第44天(2017.10.15) 周六下午,是Peter每周回家的日子。...
    星悅傳奇閱讀 411評(píng)論 0 0

友情鏈接更多精彩內(nèi)容