Css中Position定位屬性與層級關係

來源:互聯網
上載者:User

標籤:lan   head   doctype   play   back   post   relative   dex   解釋   

今天同事發現一個有意思的問題,關於position的層級關係的,他要不說我也沒注意過

測試後果然有趣,有待深入研究:

 1 <!DOCTYPE html> 2 <html> 3     <head> 4         <meta charset="UTF-8"> 5         <title>Css中Position定位屬性與層級關係</title> 6         <style type="text/css"> 7             #W{ 8                 position: relative; 9             }10             .a{position: absolute;}11             #addTR{position: relative;width: 200px;height: 30px;background: seagreen;}12         </style>13     </head>14     <body>15         <div id="w">16             <div id="addTR">17                 <p>文字</p>18             </div>19             <div class="a">20                 <img src="img/1.jpg"/>21             </div>22             <div class="a">23                 <img src="img/2.jpg"/>24             </div>25             <p style="margin-top: 500px;">26                  層級關係27                  <br />28 29 首先是遵循DOM的規則,同級的後面居上。<br />30 31 一般有定位屬性的元素會高於無定位屬性的同級元素。<br />32 33 都有定位屬性的同級元素,z-index大者居上<br />34 35 如果是非同級的元素, 則會忽略元素本身z-index,取與對比元素同級的祖先元素的z-index屬性,大者居上<br /> 36             </p>37         </div>38     </body>39 </html>

 

一個博主的回答:http://www.tuicool.com/articles/rmAzia

解釋原文:http://www.elanblog.com/2014/03/04/postion-teach/

2017-04-18  15:13:12 end

Css中Position定位屬性與層級關係

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.