问题
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