老師,只在footer設置clear:both,mainbody中不設置overflow:hidden也可以的啊,這是為什么呢
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
<style type="text/css">
* { margin: 0; padding: 0; }
#wrap { width: 960px; margin: 0 auto; background: red; }
#header { width: 100%; background: black; }
#mainbody { width: 100%; background: yellow;}
#left{width:800px; ?background:green;float:left;}
#right{width:140px; height:300px; background:blue;float:right;}
#footer{width:100%;background:pink;clear:both;}
</style>
</head>
<body>
<div id="wrap">
? <div id="header">頭部</div>
? <div id="mainbody">
? ? <div id="left">左邊</div>
? ? <div id="right">右邊</div>
? </div>
? <div id="footer">版權部分</div>
</div>
</body>
</html>
2015-09-30
你在mainbody中不設置overflow:hidden,由于它的兩個子div都浮動了,#mainbody本身就感知不到高度了。具體視角效果,你可以設置#left或#right的高度后,你觀察一下就明白了。
2015-10-17
你的代碼也沒有錯,但是有沒有發現#mainbody不見了呢,overflow:hidden是設置#mainbody這個層不受#left和#right浮動的影響
2015-10-08
#mainbody?{?width:?100%;?background:?yellow;} #left{width:800px;??background:green;float:left;} #right{width:140px;?height:300px;?background:blue;float:right;} #footer{width:100%;background:pink;clear:both;}我這樣設置之后好像沒什么變化,還是不怎么明白,請老師指出來,