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