Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7. 描述一下position #8

Open
linrunzheng opened this issue Aug 10, 2021 · 0 comments
Open

7. 描述一下position #8

linrunzheng opened this issue Aug 10, 2021 · 0 comments

Comments

@linrunzheng
Copy link
Owner

position可用于指定一个元素在文档中的定位方式,主要包含5种定位方式:

  1. static
    默认值,元素会按常规文档流进行定位,且设置top, left, right, bottom, z-index均不生效;

  2. relative
    相对于自身定位,元素首先会按常规文档流进行布局定位,之后根据其他属性值如top,left等调整元素位置,不影响其他元素的布局;

  3. absolute
    绝对定位,元素会脱离文档流且不占据空间。元素会找到最近一层的position为非static的祖先元素来进行定位,如果没有则相对于body进行定位。

  4. fixed
    固定定位,元素会脱离文档流且不占据空间。通常情况下元素会相对于浏览器的视口的位置来进行定位。如果祖先元素设置了transform, filter, perspective的值,则会相对于祖先元素进行定位而非视口。

  5. sticky
    粘性定位,简单理解就是综合了relative以及fixed,通过一个阈值决定使用哪一种方式(比如顶部导航页面滚动后吸顶效果);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant