要求。上部固定高度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會超出