困境:
我们有两个嵌套的 DIV:一个带有溢出的外部 DIV:隐藏并绝对定位内部 DIV。默认情况下,内部 DIV 不会遵循外部 DIV 的溢出行为。我们怎样才能在不将外部 DIV 的位置更改为绝对位置(这会破坏我们的布局)的情况下保持这种行为?
解决方案:
确保内部 DIV 尊重外部 DIV 的位置Overflow 属性:
示例:
#outer { width: 200px; height: 200px; background-color: green; overflow: hidden; position: relative; // Make outer DIV relative } #inner { width: 50px; height: 50px; background-color: red; position: absolute; // Keep inner DIV absolute left: 250px; top: 250px; }
附加说明:
以上是如何使绝对定位的内部 DIV 尊重其父级的 Overflow:hidden 属性?的详细内容。更多信息请关注PHP中文网其他相关文章!