視頻中的絕對定位問題,我測試的效果不一樣?。?!
首先我想問的是position: absolute;不是會將對象拖離出正常的文檔流絕對定位嗎?既然它已經脫離了正常的文檔流,它便不會占位置,那么中間的那個box2左側就不會是緊跟著左邊的box1右側開始,而是直接緊貼著瀏覽器左邊開始,反正我的測試就是這個現象的,我測試的結果是box1和box3已經脫離文檔了,不占位置了,所以box2如果不設置margin值,便會把box1和box3下面的位置占住。為了看得清楚我把box2高度設置比別的高10px
測試效果截圖:
以下我的是代碼:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Document</title>
<style type="text/css">
*{margin: 0;padding: 0;}
body{
font-family: "Microsoft YaHei";
line-height: 500px;
color: white;
font-size: 30px;
}
.f{
width: 300px;
height: 500px;
background: fuchsia;
text-align: center;
position: absolute;
top: 0;left: 0;
}
.g{
?height: 510px;
?background: seagreen;
?text-align: center;
?margin: 0 100px;
??
}
.h{
width: 400px;
height: 500px;
background: tomato;
position: absolute;
right: 0;
top: 0;
text-align: center;
}
</style>
</head>
<body>
<div>
box1
</div>
<div>
box2
</div>
<div>
box3
</div>
</body>
</html>
2016-04-02
我知道老師那個為什么了,他把中間的box的margin-left:300px 大于左邊box的寬度200px,而右margin:200px 也大于或者等于右邊的box的寬度,所以才到中間的