<!DOCTYPE?html?>
<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>
<title>混合布局</title>
<style>
body{?margin:0;?padding:0;?font-size:30px;?font-weight:bold}
div{?text-align:center;?line-height:50px}
.top{?height:100px;background:#9CF}
.head{?width:960px;margin:0?auto;height:100px;background:#F90}
.main{?width:960px;margin:0?auto;border:5px?solid?red;}
.left{?width:220px;?height:600px;?background:#ccc;float:left;}
.right{?width:740px;?height:600px;background:#FCC;?float:right}
.r_sub_left{?width:540px;?height:600px;?background:#9C3;?float:left}
.r_sub_right{?width:200px;?height:600px;?background:#9FC;?float:right;}
.footer{?height:50px;?background:#9F9;}
</style>
</head>
<body>
<div?class="top">
????<div?class="head">head</div>
</div>
<div?class="main">清楚看到mian撐開
????<div?class="left">left?</div>
????<div?class="right">
???? <div?class="r_sub_left">sub_left</div>
????????<div?class="r_sub_right">sub_right</div>
????</div>
</div>
<div?class="footer">footer</div>
</body>
</html>? ? ?1.上面的代碼沒有給main設置高度時,而main沒有內容或子元素又設置成了浮動,footer會跑到head的下面。? ? 2.當給 main中添加內容時,如“清楚看到mian撐開”,看到了塌陷的父元素main被撐開了。? ? 3.在footer類中添加? clear:both;看到footer回到底部;當添加的是clear:left時,沒有變化,當添加的是clear:right時,底部向上挪動了內容“楚看到mian撐開”的高度。問題:如何理解浮動?top,main,footer是并列元素,footer受main的影響,但是main的子元素left和right是如何影響footer的?? ??clear:left和clear:right的結果不一樣,footer是如何受到影響的?是只有? r_sub_right? 嗎?
4 回答

陽火鍋
TA貢獻16條經驗 獲得超2個贊
不知道是你思維混亂,還是我功力不夠理解不了你的意思。。
試著回答一下你的問題:1,main有內容就要設置高度,不要靠內容去撐。
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 2,你看到的main撐開是你加了一個5px的邊框線。
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 3,你想讓footer回到底部就給main加個高度就可以了。
我覺得這東西先達到效果再去理解比較重要。。反正這里不行就改那里,總會碰中一兩個。。碰著碰著就理解了。。你不要寄希望于某一個人來用文字開拓你。。自己動手,因為畢竟CSS還是比較簡單的。。我排版div的時候每個div都加一個border邊框。這樣比較直觀。。然后我也是才學1個月的新手。。

WEYN
TA貢獻5條經驗 獲得超2個贊
我以前用浮動時,解決失高的問題是在浮動元素外面加一層div,然后給這個div的高度設置成auto,overflow:auto。這樣footer就跑不到header下面了。
也就是給你.main{overflow:auto}
- 4 回答
- 0 關注
- 1948 瀏覽
相關問題推薦
添加回答
舉報
0/150
提交
取消