要实现不被父级或者爷爷级的 overflow: hidden 给隐藏的效果,可以使用 position: fixed 或者 position: absolute 来脱离文档流,从而避免被父级或者爷爷级的 overflow: hidden 影响。

例如,假设有以下 HTML 结构:

<div class="grandparent">
  <div class="parent">
    <div class="child">
      Content
    </div>
  </div>
</div>

如果 .parent.grandparentoverflow: hidden,而你希望 .child 不被隐藏,可以为 .child 添加 position: fixed 或者 position: absolute 属性:

.child {
  position: fixed;
  /* 或者使用 position: absolute; */
  top: 0;
  left: 0;
}

这样,.child 元素将脱离文档流,不受 .parent.grandparentoverflow: hidden 影响

css 定位不想被父级或者爷爷级的overflow:hidden 给隐藏

原文地址: https://www.cveoy.top/t/topic/iQET 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录