我有一個關於標題,橫幅和菜單的基本設計。菜單放在標題欄中,標題使用相同的z-index與標題位於同一圖層。無論我設置到菜單中的z-index的數量多於橫幅,菜單仍然位於橫幅的後面。以下是我所申請的代碼,我如何始終將菜單始終放在任何圖層上?如何讓一個內部塊始終在其他層上?
演示可以從http://jsfiddle.net/yckelvin/s0690n29/
HTML中找到
<div class="header">Header Area
<div class="menu">Menu Area</div>
</div>
<div class="banner">Banner</div>
CSS
div {
display: block;
position: relative;
height: 100px;
width: 100px;
}
.header {
z-index: 10;
width: 100%;
background-color: rgba(255, 0, 0, 0.5) !important;
}
.menu {
background-color: rgba(0, 255, 0, 0.5);
margin-top: 20px;
margin-left: auto;
margin-right: 5%;
height: 300px;
z-index: 20;
}
.banner {
background-color: rgba(0, 0, 255, 0.8);
margin-top -10px;
width: 100%;
z-index:10;
}
請參閱:https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Understanding_z_index/The_stacking_context和http://www.w3.org/TR/CSS21/zindex.html – 2014-10-12 08:39:15