<strike id="3tkic"><sup id="3tkic"></sup></strike>

  1. <ul id="3tkic"></ul>
      <b id="3tkic"><legend id="3tkic"></legend></b>
      <b id="3tkic"><meter id="3tkic"></meter></b>

    • <strike id="3tkic"></strike>

      <blockquote id="3tkic"></blockquote>

    • 亚洲AV无码国产在丝袜线观看_亚洲第一页A∨在线_亚洲国产人成在线观看69网站_无码日韩人妻AV一区免费l

      深入理解及應(yīng)用Position

      2016/11/4 8:42:00   閱讀:1587    發(fā)布者:1587

      position俗稱定位,主要取值及作用如下:

      static

      默認(rèn)值。沒有定位,出現(xiàn)在正常文檔流中

      absolute

      絕對(duì)定位,相對(duì)于position為absolute、relative、fixed的第一個(gè)父元素進(jìn)行定位

      relative

      相對(duì)定位,相對(duì)于其正常位置進(jìn)行定位

      fixed

      絕對(duì)定位,相對(duì)于瀏覽器窗口進(jìn)行定位

      Position本不復(fù)雜,混淆應(yīng)用比較難理解,主要規(guī)則如下:

      脫離文檔流

      除 static屬性值之外,其他值都會(huì)使元素脫離文檔流(float也會(huì)導(dǎo)致元素脫離文檔流)。

      對(duì) Width、height的影響

      1) Absolute的參考點(diǎn)為最近可作為參考點(diǎn)的父元素(position為absolute、relative、fixed的元素)、
      fixed的參考點(diǎn)瀏覽器窗口、relative的參考點(diǎn)為元素正常位置。

      2) 元素本身值為inherit時(shí)

      a) 當(dāng)父級(jí)元素的Width和height值為數(shù)值時(shí),元素繼承父級(jí)元素的完整高度,并以最近參考點(diǎn)作為參考。

      .wrap{ 
                  position: relative; 
                  width: 500px; 
                  height: 300px; 
                  border: 1px solid red; 
              } 
              .cont{ 
                  background: gray; 
                  width: 150px; 
                  overflow: hidden; 
              } 
              .txt{ 
                  background: yellow; 
                  width: 230px; 
                  height: inherit; 
              } 
              .banner{ 
                  background: pink; 
                  width: 50%; 
                  height: inherit; 
              } 
              .txt-cont{ 
                  position: absolute; 
                  background: darkblue; 
                  width: inherit; 
                  color: white; 
              }
      <div class="wrap"> 
              <div class="cont"> 
                  cont 
                  <div class="txt"> 
                      txtxtxt 
                      <div class="txt-cont"> 
                          txt-cont 
                      </div> 
                  </div> 
                  <div class="banner"> 
                      banner 
                  </div> 
              </div> 
      </div>

      b) 當(dāng)父級(jí)元素的Width和height值為百分比時(shí),以參考點(diǎn)元素的寬、高* 百分比來計(jì)算。

      .wrap{ 
                  position: relative; 
                  width: 500px; 
                  height: 300px; 
                  border: 1px solid red; 
              } 
              .cont{ 
                  background: gray; 
                  width: 150px; 
                  overflow: hidden; 
              } 
              .txt{ 
                  background: yellow; 
                  width: 50%; 
                  height: inherit; 
              } 
              .banner{ 
                  background: pink; 
                  width: 50%; 
                  height: inherit; 
              } 
              .txt-cont{ 
                  position: absolute; 
                  background: darkblue; 
                  width: inherit; 
                  color: white; 
              }
      <div class="wrap"> 
              <div class="cont"> 
                  cont 
                  <div class="txt"> 
                      txt 
                      <div class="txt-cont"> 
                          txt-cont 
                      </div> 
                  </div> 
                  <div class="banner"> 
                      banner 
                  </div> 
              </div> 
      </div>

       

      3) 元素本身為百分比時(shí)(50%)

      此種情況下,無論父級(jí)元素的width和height是數(shù)值,還是百分比都不會(huì)造成對(duì)元素自身的影響,
      元素自身還是會(huì)以參考進(jìn)行相應(yīng)的計(jì)算。

      .wrap{ 
                  position: relative; 
                  width: 500px; 
                  height: 300px; 
                  border: 1px solid red; 
              } 
              .cont{ 
                  background: gray; 
                  width: 150px; 
                  overflow: hidden; 
              } 
              .txt{ 
                  background: yellow; 
                  width: 50%; 
                  height: inherit; 
              } 
              .banner{ 
                  background: pink; 
                  width: 50%; 
                  height: inherit; 
              } 
              .txt-cont{ 
                  position: absolute; 
                  background: darkblue; 
                  width: 100%; 
                  color: white; 
              }
      <div class="wrap"> 
              <div class="cont"> 
                  cont 
                  <div class="txt"> 
                      txt 
                      <div class="txt-cont"> 
                          txt-cont 
                      </div> 
                  </div> 
                  <div class="banner"> 
                      banner 
                  </div> 
              </div> 
      </div>

      定位后的默認(rèn)位置

      Fixed和absolute屬性后的默認(rèn)位置都是在原地,只是緊跟后面折正常文檔流元素會(huì)頂上來,
      被定位元素蓋住。

      他與z-index無解的關(guān)系

      z-index的詳細(xì)介紹見后面章節(jié),此處只指出position除static值外都會(huì)創(chuàng)建層疊上下文
      (z-index不為auto的時(shí)候)。

      1) z-index為數(shù)值時(shí),會(huì)創(chuàng)建層疊上下文,子元素層疊順序以此做為參考。

      2) z-index為auto時(shí),不會(huì)創(chuàng)建層疊上下文,層疊順序與z-index:0一致。

      亚洲AV无码国产在丝袜线观看_亚洲第一页A∨在线_亚洲国产人成在线观看69网站_无码日韩人妻AV一区免费l
      <strike id="3tkic"><sup id="3tkic"></sup></strike>

      1. <ul id="3tkic"></ul>
          <b id="3tkic"><legend id="3tkic"></legend></b>
          <b id="3tkic"><meter id="3tkic"></meter></b>

        • <strike id="3tkic"></strike>

          <blockquote id="3tkic"></blockquote>

        • 渑池县| 夹江县| 太保市| 高青县| 合江县| 民权县| 锦州市| 班戈县| 鄂托克前旗| 佛冈县| 海宁市| 香格里拉县| 天水市| 龙江县| 金平| 崇明县| 莱州市| 广水市| 五莲县| 井陉县| 习水县| 扎赉特旗| 吉林市| 江城| 曲周县| 青海省| 察隅县| 崇礼县| 读书| 东宁县| 东乌珠穆沁旗| 剑川县| 保德县| 惠来县| 蓬溪县| 海伦市| 拉萨市| 东乡县| 扶余县| 宁陵县| 武冈市|