標籤:css相對定位和絕對位置
<html><head><title>css相對定位和絕對位置</title><style type = "text/css" >body,div {margin:0;padding:0;height:2000px;}#div1 { width:200px;height:200px;background-color: red;position:absolute; z-index:2;/*left:100px; top:20px;1.採用相對定位後,left和right, top和bottom只能設定一個2.相對定位,相對於原來的位置而言。設定相對定位的元素依然會佔用原 來的空間。仍在標準流中。*/}#div2 {width:200px;height:200px;background-color:#369369;position:absolute;left:20px;top:20px;z-index:-1; /*3.絕對位置,針對body頁面左上方而言的。left看不出來的, 只有top,bottom才可以看出與relative的區別4.設定為絕對位置的元素不會佔用原來的空間,會脫離標準流*/}#div3 {width:200px;height:200px;background-color:blue;/* position:fixed;left:20px;top:50px;5.固定定位,與絕對位置一樣都會脫離標準流6.固定定位,針對瀏覽器視窗而言的。absolute針對body(0,0)而言的。*/}/*重疊元素的堆疊順序 z-index ;前提是只有設定了以上三種定位才有用。設定的數值越大,堆疊越在上層。也可以用負值。*/</style><meta charset = "utf-8" /><!--<link rel = "stylesheet" style = "text/css" href = "style/css.css" />--></head><body><div id = "div1" >div1</div><div id = "div2" >div2</div><div id = "div3" >div3</div></body></html>
css相對定位和絕對位置