Skip to content

Position(位置) ​

用于控制应用程序中元素定位的实用程序。

类代表值
position-staticposition: static;
position-relativeposition: relative;
position-absoluteposition: absolute;
position-fixedposition: fixed;
position-stickyposition: sticky;
top-0top: 0;
right-0right: 0;
bottom-0bottom: 0;
left-0left: 0;

使用 ​

position(位置)实用程序允许您快速设置任何元素的定位样式。这些类可用于将position和 top, right, bottom, and left属性应用于元素。

Static (静态的) ​

所有元素的默认位置值都是static。这意味着元素是根据文档的正常流程定位的。top, right, bottom和 left属性对静态定位的元素没有影响。

Relative (相对的) ​

position-relative类允许您相对于元素在文档中的正常位置定位元素。这意味着可以使用top, right, bottom, 和 left属性将元素从其正常位置移动。

Absolute (绝对定位) ​

position-absolute类允许您相对于其最近的父元素定位元素。如果没有找到定位的祖先,则元素相对于文档主体定位。

Fixed (固定的) ​

position-fixed类允许您相对于视窗定位元素。这意味着即使滚动页面,元素也会保持在相同的位置。

Sticky (粘连) ​

position-sticky类允许您根据用户的滚动位置来定位元素。元素被视为relative相对的,直到它越过指定的阈值,此时它被视为fixed固定的。