css中元素的定位:position

來源:互聯網
上載者:User
文章目錄
  • static
  • fixed
  • relative
  • absolute
  • clip
  • z-index

網頁中元素的定位使用position屬性。position的可用值有:

static

預設值。沒有定位,元素出現在正常的流中(忽略 top, bottom, left, right 或者 z-index 聲明)。

 

fixed

產生絕對位置的元素,相對於瀏覽器視窗進行定位。

元素的位置通過 "left", "top", "right" 以及 "bottom" 屬性進行規定。

 

relative

產生相對定位的元素,相對於其正常位置進行定位。

因此,"left:20" 會向元素的 LEFT 位置添加 20 像素。

 

absolute

產生絕對位置的元素,相對於 static 定位以外的第一個父元素進行定位。

元素的位置通過 "left", "top", "right" 以及 "bottom" 屬性進行規定。

 

clip

對元素進行裁剪

clip:rect(0px 50px 200px 0px)

 

z-index

預設為0,通過設定z-index,可以設定元素疊加時的顯示順序。

相關文章

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.