z-indexing浮动div

Pre*_*ton 16 css z-index css-float

我有两个div浮动:左.我z-index第一个div在上面,但它不起作用.这是因为浮动元素没有定位?

<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>
Run Code Online (Sandbox Code Playgroud)

ano*_*ery 32

您需要设置position属性.添加position:relative#menu显示拇指上方的菜单div.