div相对重叠

时间:2013-03-12 09:46:13

标签: html css positioning relativelayout overlap

我有3个div。我需要得到这些重叠,但我 不能使用绝对定位 。我怎样才能做到这一点? 我的目标是使用响应式布局(无修复px值

    <div id="hold" style="background-color: #CCCCCC;padding: 10px">
        <div id="first" style="width: 100px;height: 100px;background-color: red;z-index: 1"></div>
        <div id="sec" style="width: 100px;height: 100px;background-color: greenyellow;z-index: 3"></div>
        <div id="third" style="width: 100px;height: 100px;background-color: #a3dbec;z-index: 5"></div>
    </div>

我使用了以下css。

        #first,#sec,#third{
            margin: 0 auto;
            position: relative;
            top: 0;
        }

1 个答案:

答案 0 :(得分:3)

设置margin-top

#sec
{
    margin-top: -100px;
}
#third
{
    margin-top: -100px;
}

http://jsfiddle.net/EPq6Z/