上下固定中間滾動布局(flex/absolute)

好久沒更新簡書啦,最近真的是忙懵B了,趕緊記錄一下知識點(diǎn):

html:

<div class="wrap">
      <div class="header">header</div>
      <div class="main">
       彈性滾動區(qū)域
      </div>
      <div class="footer">footer</div>
</div>

flex實(shí)現(xiàn)上下固定中間滾動布局

css:

*{
    margin:0;
    padding:0;
}
html,body{
    height:100%;
}
.wrap{
    display:-webkit-box;
    display:-webkit-flex;
    display:-ms-flexbox;
    display:flex;
    -webkit-box-orient:vertical;
    -webkit-flex-direction:column;
    -ms-flex-direction:column;
    flex-direction:column;
    width:100%;
    height:100%;
}
.header,.footer{
    height:40px;
    line-height:40px;
    text-align: center;
    background-color:#D8D8D8;
    text-align:center;
}
.main{
    -webkit-box-flex:1;
    -webkit-flex:1;
    -ms-flex:1;
    flex:1;
    width:100%;
    padding:10px;
    box-sizing: border-box;
}

position:absolute實(shí)現(xiàn)上下固定中間滾動布局

css:

*{ padding:0; margin:0; }
html,body{height:100%;}
.wrap{width:100%;}
.header,.footer{height:40px;line-height:40px;background-color:#D8D8D8;text-align:center;}
.header{position: absolute;top:0;left:0;width:100%;}
.footer{position: absolute;bottom:0;left:0;width:100%;}
.main{position:absolute;z-index:1;top:40px;left:0;bottom:40px;width:100%;}

點(diǎn)擊查看原文

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

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

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