我的代碼如下所示:使用z-index在其他元素前面創建一個嵌套元素?
css:
.top {
position: absolute;
top:0;
left:0;
height: 1600px;
width: 100%;
z-index: -100;
}
.bar {
position: relative;
z-index: -200;
width: 100%
height: 100px;
}
.inner-bar {
position: relative;
z-index: 100;
width: 100%
height: 50px;
}
html:
<body>
<div class="top">some content</div>
<div class="bar">
<div class="inner-bar">some content</div>
<div>
</body>
正如你可以看到,我試圖讓內酒吧出現在面前,但這不起作用。一旦我將酒吧設置在所有事物的後面(這是有效的),這也將內部酒吧設置在任何事物的後面,而不管我爲內部酒吧做什麼樣式。我的佈局要求內部酒吧必須是酒吧的孩子。那麼有沒有解決方案,它是什麼?
爲了說清楚我的目標是讓酒吧在頂部出現(頂部的內容出現在酒吧上)並讓內部酒吧背後(頂部的內容隱藏,如果它與內部酒吧重疊,以便內部的鏈接-bar是活動的)。
你'的z-index:-200'爲' .bar'如何在'.top'前面有'z-index:-100'?如果理解正確,則必須刪除'.bar'的'z-index'並僅使用'.inner-bar'的'z-index'。 – Sotiris 2011-02-28 15:46:18
你有沒有試過這個:http://stackoverflow.com/questions/361359/how-can-i-get-desired-z-index-behavior-from-ie-when-using-nested-divs – corroded 2011-02-28 15:47:08
使用負面的' z-index'通常以* something *爲無法選擇或不可點擊結束。由於這種非常惱人的趨勢,最好謹慎使用。 – thirtydot 2011-02-28 15:50:04