z-indexing floating divs

风流意气都作罢 提交于 2021-02-17 21:27:36

问题


I have two divs float:left. I z-index the first div to be above, but it doesn't work. Is this because floated elements are not positioned?

<html>

<style>
    #wrap{
        background:#666;
    }

    #menu, #thumbs{
        float:left;
    }

    #menu{
        background:#06C;
        z-index:10;
    }
    #thumbs{
        background:#0CF;
        margin-left:-20px;
    }

</style>
</head>

<body>

<div id="wrap">
    <div id="menu">
    <p>menu</p>
    </div>
    <div id="thumbs">
    <p>thumbs</p>
    </div>
</div>


</body>
</html>

回答1:


You need to set the position property. Adding position:relative to #menu displays the menu div above thumbs.



来源:https://stackoverflow.com/questions/5018572/z-indexing-floating-divs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!