不對父元素mainbody清除浮動,而是對footer用clear:both清除浮動
不對父元素mainbody清除浮動,而是對footer用clear:both清除浮動,為什么mainbody顏色變了,這顏色怎么來的?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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 {
background:#00C;
margin:0 auto;
width:960px;
}
#header {
background:#FF3300;
width:100%;
}
#mainbody {
? ?background:#FC0;
}
.left {
width:800px;
height:200px;
background:#000;
float:left;
}
.right {
width:140px;
height:500px;
background:#690;
float:right;
}
#footer {
background:#639;
width:100%;
? ? clear:both;
}
</style>
</head>
<body>
<div id="wrap">
? <div id="header">頭部</div>
? <div id="mainbody">
? ? <div class="left"></div>
? ? <div class="right"></div>
? </div>
? <div id="footer">版權部分</div>
</div>
</body>
</html>
2016-08-05
首先 clean:both 這個適用于對于后模塊有影響的本模塊里,mainbody里面有兩個模塊,第二個模塊對footer有了影響,所以加clean:both 按理應該在mainbody的第二個模塊里。 ?將clean加在footer里,改變了整個板塊布局 ,顏色也就變成總的也就是wrap 里設置的顏色了。而mainbody的顏色被藏在了它的兩個模塊的背后~?
2016-08-16
你可以使用火狐瀏覽器查看,然后用火狐瀏覽器的firebug看對footer清除浮動前以及清除浮動后,wrap高度的變化就更清楚啦,一目了然!