CSS 如果父元素溢出:隐藏,如何使子元素可见?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17695252/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:32:48  来源:igfitidea点击:

How to make a child element visible if the parent is overflow:hidden?

cssoverflow

提问by Mustapha Aoussar

I have a child element with overflow:visible;and the parent element with overflow:hidden;. The child element has height higher than the parent element.

我有一个子元素overflow:visible;和父元素overflow:hidden;。子元素的高度高于父元素。

Why the child element is hidden if has the property overflowset to visible?

如果将属性溢出设置为可见,为什么子元素被隐藏?

HTML:

HTML:

<div id="container">
    <div id="makeThisVisible"></div>
    <div id="thisRemainsHidden"></div>
</div> 

CSS:

CSS:

#container {
    width: 500px;
    height: 100px;
    border: 1px solid black;
    background: Gray;
    /*OVERFLOW*/
    overflow: hidden;
}
#makeThisVisible {
    width: 240px;
    height: 300px;
    float: left;
    border: 1px solid red;
    background: IndianRed;
    /*OVERFLOW*/
    overflow: visible;
    margin-left: 8px;
}
#thisRemainsHidden {
    width: 240px;
    height: 300px;
    float: left;
    border: 1px solid teal;
    background: DarkCyan;
}

The fiddle: http://jsfiddle.net/ewNbu/

小提琴:http: //jsfiddle.net/ewNbu/

To resolve this issue i don't want to use visibility property for #containeror position:absolute property for #makeThisVisible, but I want to find another better way to solve the problem.

为了解决这个问题,我不想对#container或 position:absolute 属性使用可见性属性#makeThisVisible,但我想找到另一种更好的方法来解决这个问题。

Please help! Thank you so much.

请帮忙!非常感谢。

回答by user2276428

You can try playing with:

您可以尝试玩:

position:absolute;

which breaks the child out of the scope of the parent element.

这使子元素脱离了父元素的范围。

DEMO

演示