在溢出隐藏的父元素上显示绝对定位的子元素强制?

时间:2015-08-05 12:28:11

标签: css overflow hidden

有什么方法可以在溢出隐藏的父元素上显示绝对定位的子元素强制?以下是我正在尝试的代码段。

div{
    position: relative;
    width: 200px;
    height: 200px;
    overflow: hidden;
    border: 1px solid #ccc;
}

div span{
    position: absolute;
    top: 10px;
    right: -25px;
    display: block;
    width: 50px;
    height: 50px;
    background: #444;
}

div p{
    padding: 10px;
}

<div>
    <span></span>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p>
</div>

这是小提琴链接http://jsfiddle.net/2m93zbhL/

1 个答案:

答案 0 :(得分:0)

不,不是。

只需添加另一个div:

<div class="wrapper">
        <span></span>
        <div class="container">
            <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p>
        </div>
    </div>

并将“overflow:hidden”属性放在内部div:

.wrapper{
        position: relative;
        width: 200px;
        height: 200px;
        border: 1px solid #ccc;
    }

    .container{
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        width: 100%;
        overflow: hidden;
    }

    .wrapper span{
        position: absolute;
        top: 10px;
        right: -25px;
        display: block;
        width: 50px;
        height: 50px;
        background: #444;
    }

看到这个小提琴:http://jsfiddle.net/2m93zbhL/1/