關于margin的問題,希望給出準確的答案
<!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{height:100px; background-color: #FC0;}
.main{height:500px; background-color: #f00;}
.left{height:500px; width: 200px; background-color: blue;position: absolute;top: 100px; left: 0px;}
.right{height: 500px; margin-left: 210px;background-color: #9C9; }
.foot{height: 60px;background-color: #FF5;}
</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>
上面right里面的margin-left是說這個div跟父div之間的左外邊距,可是left是跟right相鄰的div,為什么不是margin-left為10px
2016-04-19
html結構中,right在前,left在后。
如果left不加浮動屬性的話,可以看到,left是在right下面的,
回到問題來,right的左邊不是left,而且父div。所以margin-left的屬性不是相對于left的做的作用,所以僅10px是不夠的。
測試一下,
在代碼中注釋left的div,你會看到margin-left為210的right位置沒有變化,為什么?因為他的位置和left沒有關系