【发布时间】:2011-01-22 05:48:41
【问题描述】:
IE 再次被证明是我存在的祸根。我正在处理的网站顶部有一个水平菜单,其中的一项触发纯 CSS 菜单,该菜单在父菜单 DIV 中绝对定位(相对定位)。这会将菜单完美地放置在 IE 和 W3C 兼容的浏览器中。
当我在页面下方有更多定位元素时,就会出现问题。这些也是相对定位的,因为它们内部的数据需要绝对定位...再次,这在我测试过的所有浏览器中都能正常显示。
问题是,然后打开顶部菜单,部分被页面下方的定位元素遮挡 - 实际上,即使在所有元素上都定义了 z-index 属性,它也被定位在这些元素之下。 (在 CSS 文件和内联文件中)。
让 IE 正确显示此内容的唯一方法是将菜单的实际 HTML 放置在页面底部,在页面其他位置的定位元素下方(以 DOM 术语)。我只会将此作为绝对的最后手段。
所有元素都是同一类型 (div)。这是相关的 HTML:
<div id='menu'>
<div id='cat_menu' style='display:none;z-index:10000;'>
<table cellspacing='0' cellpadding='0' class='brmenu' width='100%'>
[data]
</table>
</div>
<div class='product_new' style='z-index:20;'>[data]</div>
<div class='product_listing' style='background-color:#FFFFFF;'>[data]</div>
以及相关的 CSS:
div#menu {
height: 26px;
padding: 0;
position: relative;
}
div#cat_menu {
position: absolute;
top: 25px;
left: 115px;
width: 300px;
z-index: 1000;
}
div.product_new {
background-image: url("/images/sp_images.png");
background-position: 0 -108px;
background-repeat: no-repeat;
padding 0px;
height: 40px;
font-size: 9pt;
margin-top: 5px;
position: relative;
z-index: 20;
}
【问题讨论】:
-
我正在使用原型框架,所以我不喜欢使用任何 jQuery,尤其是一次性使用。
标签: css internet-explorer z-index