關於定位的總結

position的幾種取值:static(默認),relative,absolute,fixed,sticky
static:
默認值,not positioned,正常文檔流。此時top,right,left,bottom,z-index等無效
relative:
相對於原本該在的位置進行移動,可是文檔流仍是原來的位置。能夠用其來實現居中。
absolute:
相對於前一個非static祖先元素進行定位,此時元素脫離了文檔流。能夠結合translate實現水平,垂直居中。
fixed:
相對於瀏覽器定位,此時文檔脫離了文檔流。瀏覽器

相關文章
相關標籤/搜索