css postion 屬性區別【原】

來源:互聯網
上載者:User

標籤:效果   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 屬性區別【原】

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.