相对和绝对位置的Z指数?

时间:2011-10-19 19:41:54

标签: css

似乎z-index不适用于具有绝对位置且相对于另一个div的div?我希望具有绝对位置的div低于另一个,但我只是相反。有办法解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

This example会显示代码,使一个div显示在另一个div的上方。

HTML

<div class="one">On top!</div>
<div class="two">Underneath</div>

CSS

.one
{
    height: 100px;
    width: 100px;
    background-color: #ff0;
    position: absolute;
    top: 5px;
    left: 10px;
    z-index: 1;
}

.two
{
    height: 100px;
    width: 100px;
    background-color: #f0f;
    position: relative;
    left: 10px;
    z-imdex: 2;
}

更新:仅使用定位来获得您想要的效果。

Look here

相关问题