position

介绍

position属性用于指定一个元素在文档中的定位方式。
toprightbottomleft属性一起决定元素的最终位置。

取值

  • relative 默认值。 当前 view 将参与父节点排版,top 等属性将在排版所得基础上添加相对偏移。细节点击positioning

  • absolute 当前 view 将 参与父节点排版,当前 view 会在子元素的 content bound 中进行绝对布局,即由 top 等属性决定其位置。 细节点击positioning

  • fixed 当前 view 将 参与父节点排版,当前 view 将被视为根节点的子元素进行绝对布局,即由 top 等属性决定其位置。细节点击positioning

  • 默认值 relative

样例:

position: relative;
position: fixed;
position: absolute;
1
2
3

标准化语法

relative | absolute | fixed | sticky
1

与 Web 的区别

暂时不支持 inherit、initial、revert、unset、static 等取值。

扩展阅读

toprightbottomleft

Last Updated: 2022/7/15 下午7:22:06