绝对位置vs溢出隐藏

时间:2014-06-05 09:52:18

标签: css

为什么我的div定位为绝对没有离开流程并被妈妈隐藏她的溢出设置隐藏? 我怎样才能将我的div定位为绝对? 这是FIDDLE

HTML:

<div class="div1">
    <div class="div2">        
        <div class="div3">ccccc</div>
    </div>   
</div>

CSS:

.div1 {
    overflow: hidden;
    width: 60px;
    height: 20px;
    background-color: antiquewhite;
}

.div2 {
    position: relative;
}

.div3 {
    position: absolute;
    right: -10px;
}

1 个答案:

答案 0 :(得分:0)

你的问题是你的&#34; div3&#34;类。

试试这个:

.div3 {
    position: absolute;
}

这应该很合适。

现在,如果你想让它居中,那就去吧:

.div3 {
    position: absolute;
    width: 100%;
    text-align: center;
}

编辑: 如果你坚持,那么最简单的就是在同一个元素上有一个计数器。然后试试这个:

.div3 {
    position: absolute;
    right: -10px;
    padding-right: 10px;
}

希望这有帮助。

相关问题