亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

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}


正在回答

4 回答

.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設置的是層疊級別


0 回復 有任何疑惑可以回復我~

你的頭部,底部都加了absolute 絕對定位,使頭部,底部脫離了文檔流,不占空間。所以頭部,底部都跟中間的div重疊了

0 回復 有任何疑惑可以回復我~
#1

群下之辰 提問者

那該怎么解決呢?
2016-04-12 回復 有任何疑惑可以回復我~
<html>
?<head>
????<title>首頁</title>
?????<style?type="text/css">
?????????body{margin:0;padding:0;position:?relative}
?????????.header{width:?100%;height:?80px;background-color:?#303030;position:absolute;top:0;z-index:2;opacity:?.8}
?????????.center{height:?100%;}
?????????.left{width:?320px;height:?inherit;float:?left;background-color:?aquamarine}
?????????.right{width:?auto;height:?inherit;background-color:?#FF9400}
?????????.footer{width:?100%;height:?21px;border-top:1px?solid?#f0f0f0;background-color:white;position:?absolute;bottom:0;z-index:?1;opacity:?.8}
?????????span{font-size:11px;line-height:?21px;text-align:?center;display:?block}
?????</style>
?</head>
?<body>
???<div?class="header">頭部</div>
???<div?class="center">
???????<div?class="left">左部</div>
???????<div?class="right">右部</div>
???</div>
???<div?class="footer"><span>底部</span></div>
?</body>
</html>

http://img1.sycdn.imooc.com//570c7ffe00013ef009360632.jpg

運行之后的效果就是這樣子的,我想要的不是這種效果

0 回復 有任何疑惑可以回復我~

你好,設置absolute絕對定位時,需要將父元素設置為相對定位(不設置偏移屬性),即添加 body { position: relative; }

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
如何用CSS進行網頁布局
  • 參與學習       209566    人
  • 解答問題       1206    個

用最簡潔的案例教你布局的那些知識,這是前端工程師基本技能

進入課程

3行垂直布局問題

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號