gpt4 book ai didi

html - 当中间元素溢出时如何使元素相对于外部元素具有粘性 : hidden;?

转载 作者:太空宇宙 更新时间:2023-11-04 07:53:20 24 4
gpt4 key购买 nike

考虑这个 HTML:

<div style="height: 200px; overflow: auto;">
<div style="height: 500px; overflow: hidden;">
<p style="position: sticky">
some sticky content
</p>
</div>
</div>

在此代码段中,<p > 由于 overflow: hidden 相对于内部 div 是粘性的.是否可以制作 <p>粘性相对于外部 div 没有:

  • 删除 overflow: hidden
  • 移动 <p>跳出内部div

最佳答案

Is it possible to make the <p> sticky relative to the outer div without:

  • removing the overflow: hidden
  • moving the <p> out of the inner div

目前,这不可能 - 请参阅 MDN :

Note that sticky, by specification, will not work inside element with overflow: hidden or auto. (ref: Github issue on W3C CSSWG)

也就是说,在上面的 Github 问题中,讨论了这个限制实际上是根据规范还是实际上是一个错误。

关于html - 当中间元素溢出时如何使元素相对于外部元素具有粘性 : hidden;?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47548123/

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