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

position #17

Open
Ben-yby opened this issue Dec 15, 2020 · 0 comments
Open

position #17

Ben-yby opened this issue Dec 15, 2020 · 0 comments

Comments

@Ben-yby
Copy link
Owner

Ben-yby commented Dec 15, 2020

position

static

为默认值,指示元素出现在正常的文档流中;

相对定位(relative)

相对于该元素在文档流中的正常位置进行偏移定位,原占位仍保留(即不脱离文档流)。

绝对定位(absolute)

相对于static定位以外的最邻近父级元素进行偏移定位,即相对于其直接父级元素。注意:脱离了文档流

固定定位(fixed)

相对于浏览器窗口进行定位,即固定定位是以浏览器窗口的最左上点作为基点进行偏移定位的。其位置随时跟随浏览器大小的变化而移动,因此应用得很少。主要运行于浏览器窗口的贴边定位。绝对定位(absolute)同样可以应用在固定定位的框架层里面。

粘性定位(sticky)

position:relative和position:fixed的结合体——当元素在屏幕内,表现为relative,就要滚出显示器屏幕的时候,表现为fixed。

注意事项

  1. 父级元素不能有任何overflow:visible以外的overflow设置,否则没有粘滞效果。因为改变了滚动容器(即使没有出现滚动条)。因此,如果你的position:sticky无效,看看是不是某一个祖先元素设置了overflow:hidden,移除之即可。
  2. 父级元素设置和粘性定位元素等高的固定的height高度值,或者高度计算值和粘性定位元素高度一样,也没有粘滞效果。
  3. sticky定位,不仅可以设置top,基于滚动容器上边缘定位;还可以设置bottom,也就是相对底部粘滞。如果是水平滚动,也可以设置left和right值。
  4. 同一个父容器中的sticky元素,如果定位值相等,则会重叠;如果属于不同父元素,且这些父元素正好紧密相连,则会鸠占鹊巢,挤开原来的元素,形成依次占位的效果。
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