main中的righ塊,增加了右浮動,margin-left就不起作用了
<!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">
body{ margin:0; padding:0; font-size:30px; color:#fff}
.top{background:grey;height:100px;}
.main{background:red;height:400px;}
.left{ background:blue;width:200px;position:absolute;left:0;top:100px;height:400px;}
.right{background:green;float:right;margin-left:210px;height:400px;}
.foot{clear:both;background:orange;}
</style>
</head>
<body>
<div class="top">top</div>
<div class="main">
? ? <div class="right">right</div>
? ? <div class="left">left</div>
</div>
<div class="foot">foot</div>
</body>
</html>
誰能給我解析下為什么?
浮動不是也是成為了一個塊嗎?為何做外邊距沒有作用了?
2015-10-24
肯定是啊 都浮動了 沒有參照物了
2015-10-23
其實是有作用的,只是因為你右側的盒子左邊什么都沒有。。你設置這個margin-left根本不會去改變什么。你在right盒子的左側放一個盒子,再改變你的margin-left,就可以看出效果來了。
2015-10-23
main中,左邊的left是絕對定位,距離左邊為0;右邊的right是右浮動,距離右邊為0.那么你這個時候,設置right的margin-left的時候,其實是相對于main的左邊框的。210px加上right的width顯然不會超過main的總寬度。所以你看不到效果