gpt4 book ai didi

css - 位置 :sticky does not leave parent

转载 作者:技术小花猫 更新时间:2023-10-29 11:18:02 25 4
gpt4 key购买 nike

如何使元素具有粘性,使其停留在视口(viewport)的顶部?我希望元素即使离开容器也能保持粘性。

我试过了

HTML

<div class="page">
<div class="parent">
<div class="child-sticky">
<p>i want to be sticky, even when I'm outside my parent.</p>
</div>
</div>
</div>

CSS

.child-sticky {
position:sticky;
top:20px;
}

.page {
height: 3000px;
}

这里有一支笔来说明问题。向下滚动以了解我的意思。

https://codepen.io/pwkip/pen/OxeMao

最佳答案

Sticky 以这种方式工作,它将相对于其父级保持 sticky。您需要使用 fixedCheck this codepen

关于css - 位置 :sticky does not leave parent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46913063/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com