css——position


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
<style type="text/css" >
.c1{ position:absolute; width:400px; height:400px; border:1px #0000FF solid;}
.c2{position:relative; top:500px; background:#0099FF;border:1px #0000FF solid;width:120px; height:120px;}
.c3{position:relative; background:#00CC00;border:1px #00CC00 solid;width:120px; height:120px;}
</style>
</head>

<body>
<div class="c1">

</div>    
<div class="c2">
</div>
<div class="c3">
</div>
</body>

</html>

relative屬性相對比較簡單,我們要搞清它是相對哪個對象來進行偏移的。答案是它本身的位置。這就是綠色塊爲什麼在這裏,而不是跑到藍色塊下面了,因爲藍色塊在沒有top時,就在綠色塊的上面,綠色塊一直呆在老地方

<div class="c1">

</div>    
<div class="c2">
</div>
<div class="c3">

</div> 如果改爲這樣,效果還是一樣的。因爲absolutely的都脫離了文檔流。


<!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=gb2312" />
<title>無標題文檔</title>
<style type="text/css" >
.c1{ position:relative;改爲absolute也一樣 width:400px; height:400px; border:1px #0000FF solid;}
.c2{position:absolute; top:500px; background:#0099FF;border:1px #0000FF solid;width:120px; height:120px;}
.c3{position:relative; background:#00CC00;border:1px #00CC00 solid;width:120px; height:120px;}
</style>
</head>

<body>
<div class="c1">
<div class="c2">
</div>
<div class="c3">
</div>
</div>    

</body>
</html>

時效果
因爲absolutely的都脫離了文檔流。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章