2010-09-10 153 views
0

我有一個基於絕對定位和標題區域中基於CSS的菜單的佈局。在Firefox中一切正常,但在Internet Explorer 7 8中,菜單下拉菜單由內容區域覆蓋。在這種情況下,IE根本不尊重z-index屬性。IE7/8可以顯示位置:位置前的相對元素:絕對位置?

我讀了關於堆疊上下文和z-index bug,但仍然無法使其工作。有沒有辦法在#content上刪除position:absolute以解決問題?不過,我可以更改用於導航區域的定位方法。

這裏的簡化代碼:

<!DOCTYPE html> 
<html> 
<head> 
<style> 
#nav {margin:0; padding: 0; position: absolute; left: 0; top: 0; right: 0; height: 2em; background: #eee} 
#nav > li {float: left; list-style: none; position: relative; } 
#nav > li > a {display: block; position: relative; margin: 0; background-color: #eee; padding: 5px; border: 1px solid #eee; text-decoration: none; color: #444;} 
#nav > li:hover > a { background-color: #ddd; } 

#nav li ul { z-index: 1; display: none; position: absolute; padding: 0; margin: 0; list-style: none; border: 1px solid black; background: #eee; width: 100px; } 
#nav li:hover ul {display: inline;} 
#nav li ul li {list-style: none; margin: 0; padding: 0; height: 5em; } 
#nav li ul li a {display: block; padding: 5px; margin: 0; color: #444; text-decoration: none; white-space: nowrap;} 

#content { position: absolute; top: 3em; left: 0; right: 0; bottom: 0; background: #ccc; } 
</style> 
</head> 
<body> 

<ul id="nav"> 
    <li><a href="#">A</a><ul><li>...</li></ul></li> 
    <li><a href="#">Group B</a><ul><li>...</li></ul></li> 
    <li><a href="#">The third group</a><ul><li>...</li></ul></li> 
</ul> 

<div id="content"></div> 

</body> 
</html> 

回答

0

好吧,沒關係。在#nav#content(分別是2和1)上分別加上一個明確的z-index這個技巧。請注意,以上代碼中上的z-index不是必需的。

相關問題