css實現高度自適應


要求。上部固定高度50px,下部分自適應剩下整個屏幕

html, body {
    height: 100%;
    margin: 0px;
    padding: 0px;
}
#main {
    background-color: #999;
    height: 100%;
} 

#nav {
    background-color: #85d989;
    width: 100%;
    height: 50px;
}
#content {
    background-color: #cc85d9;
    width: 100%;
    position: absolute;
    top: 50px;
    bottom: 0px;
    left: 0px;
}

 

高度自適應百分比

.main {
  overflow: hidden;
  height: 0;
  padding-bottom: 50%;  這個是相對於寬度    
}

 1高度自適應遇到問題

//當父元素設置寬高自適應后。子元素設置width100%后
//子元素的子元素布局要注意
//因為默認是標准模型  內容寬度為實際寬度  pading和margin會超出

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM