這裏是小提琴:http://jsfiddle.net/hrQG6/Z-index嵌套絕對元素重疊相似的絕對元素?
HTML
<div id='map'>
<div class='hotspot' id='hs1'>
<div class='info-window'>
Foobar
</div>
</div>
<div class='hotspot' id='hs2'>
<div class='info-window'>
Foobar
</div>
</div>
</div>
CSS
.hotspot {
position: absolute;
z-index: 10;
background-color: blue;
height: 30px;
width: 30px;
}
.info-window {
display: none;
height: 250px;
width: 250px;
background-color: green;
position: absolute;
z-index: 9999;
}
的.hotspot
元素顯示在容器中。 .info-window
元素默認情況下不顯示。點擊.hotspot
將顯示相應的.info-window
。不過,我希望.info-window
覆蓋其下的任何.hotspot
元素。
相反,.hotspot
元件在的.info-window
元件的頂部。從概念上講,我誤解了position
和z-index
的使用。
[1]:除非你是F * CKIN'綠巨人,這有點讓這個比喻沒有實際意義。 –
+1我非常感謝解釋。我已經嘗試了這一點,並更好地理解了嵌套元素的z-index屬性。 – Josh
有了接受的答案,它就像沒有爲'.hotspot'指定z-index一樣簡單。這是否有缺點?我首先指定了一個,這樣它肯定在'#map'的*頂部*上。 – Josh