3行垂直布局問題
如果想上下固定,中間自適應怎么布局?我寫的中間的div穿透了底部
<div?class="header"></div> ?<div?class="center"> ?????<div?class="left"?id="left">左邊</div> ?????<div?class="right">右邊</div> ?</div> <div?class="footer">底部</div> .header{width:?100%;height:?80px;background-color:?#303030;position:?absolute;top:0;left:0;z-index:?2;opacity:?0.3} .center{background-color:?white;margin-top:?80px;margin-bottom:?22px;} .left{width:320px;height:?100%;float:left;background-color:?yellowgreen;} .right{width:auto;height:100%;background-color:?orange} .footer{width:100%;height:?21px;border-top:1px?solid?#d0d0d0;background-color:#f0f0f0;position:?absolute;bottom:?0;left:0;z-index:?1}
2016-04-13
.header{width: 100%;height: 80px;background-color: #303030;position:absolute;top:0;z-index:2;opacity: .8}
.footer{width: 100%;height: 21px;border-top:1px solid #f0f0f0;background-color:white;position: absolute;bottom:0;z-index: 1;opacity: .8}
上面2行改成
.header{width: 100%;height: 80px;background-color: #303030;}
.footer{width: 100%;height: 21px;border-top:1px solid #f0f0f0;background-color:white;}
opacity是設置不透明級別的
z-index設置的是層疊級別
2016-04-12
你的頭部,底部都加了absolute 絕對定位,使頭部,底部脫離了文檔流,不占空間。所以頭部,底部都跟中間的div重疊了
2016-04-12
運行之后的效果就是這樣子的,我想要的不是這種效果
2016-04-12
你好,設置absolute絕對定位時,需要將父元素設置為相對定位(不設置偏移屬性),即添加 body { position: relative; }