標籤:效果 tran z-index html 存在 blog dtd round fixed
CSS樣式中的postion元素有四個屬性,即static | absolute | fixed | relative。
static:
預設值。無特殊定位,遵循HTML基本定位規則 。
fixed:
固定定位,參照位置是瀏覽器視窗的左上方,即座標點為(0px, 0px);
relative :
對象不可層疊,但將依據 left , right , top , bottom 等屬性在正常文檔流中位移位置
absolute:
絕對位置,參展位置是離當前元素最近的定位方式為fixed,absolute,relative的祖先原則的左上方。
將對象從文檔流中拖出,使用 left , right , top , bottom 等屬性相對於其最接近的一個最有定位設定的父物件進行絕對位置。如果不存在這樣的父物件,則依據 body 對象。而其層疊通過 z-index 屬性定義。
範例程式碼:
<!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=gbk" /><title>fixed和relative和absolute的區別</title><style type="text/css"> body{color:black;} #static {position:static; left:100px;top:100px;width:100px; height:100px; border:1px solid black;} #fixed {position:fixed; left:100px;top:100px;width:100px; height:100px; background:red;} #relative{position:relative;left:100px;top:100px;width:900px; height:900px; border:1px solid blue;} #absolute{position:absolute;left:100px;top:100px;width:100px; height:100px; background:yellow;}</style></head><body> <div id="static">預設static</div> <div id="fixed">fixed固定不變</div> <div id="relative">relative滾動 <div id="absolute">absolute滾動</div> </div> </body></html>
:
css postion 屬性區別【原】