HTML/CSS IE 不显示我的下拉菜单 z-index 相关

发布于 2024-11-01 08:08:00 字数 866 浏览 1 评论 0原文

由于某种原因,当我在任何数字的标题中添加 z-index 时,我无法在 IE 上显示下拉菜单。当我删除它时,它就起作用了。然而,在 Firefox 和 Chrome 中,下拉列表会出现在容器和内容后面。所以要么把它拿出来,要么留在里面,我似乎无法满足所有浏览器。所以我尝试制作一个没有 z-index 的单独 IE 样式表,但这也不起作用。我知道单独的 IE CSS 正在工作,因为我更改了背景,但它使用主样式表中的下拉菜单。

网站是 www.stingrayimages.ca

感谢您的帮助

编辑:因此,我们只能说我可以在 IE 上正常工作,因为总是 IE 会出现问题。但现在下拉菜单出现在其他浏览器(如 Firefox 和 Chrome)的内容后面。我所做的就是删除 #head div 中的 z-index。无论如何要修复下拉菜单而不将 z-index 添加到 head div 吗?

编辑:我让下拉菜单可以在 IE9、firefox 和 chrome 上使用。不是IE 6,它就爆炸了。

#head {
    position:relative;
    height: 140px;
    width: 100%;
    background: #FFF;
    filter:alpha(opacity=93);
    padding-top:20px;
    /* CSS3 standard */
    opacity:0.93;
    -moz-box-shadow: 0 0 5px black;
    -webkit-box-shadow: 0 0 5px black;
    box-shadow: 0 0 5px black;
    z-index:1;
}

For some reason I cannot display the dropdown menu on IE when I add a z-index in the header of any number. When I remove it, it works. However the dropdown then appears behind the container and content in Firefox and Chrome. So either I take it out or leave it in, I cant seem to satisfy all browsers. So i tried making a separate IE stylesheet without the z-index but that doesnt work either. I know the separate IE CSS is working because I changed the backgrounds but it uses the dropdown menu in the master stylesheet.

Website is www.stingrayimages.ca

Thank you for your help

Edit: So lets just say i got it all to work on IE since its always IE that gives the problems. But now the dropdown menu appears behind the content on other browsers like firefox and chrome. All i did was remove the z-index in the #head div. Anyway to fix the dropdown menu without adding z-index to the head div?

Edit: I got the dropdown to work on IE9 firefox and chrome. Not IE 6, it just blew up.

#head {
    position:relative;
    height: 140px;
    width: 100%;
    background: #FFF;
    filter:alpha(opacity=93);
    padding-top:20px;
    /* CSS3 standard */
    opacity:0.93;
    -moz-box-shadow: 0 0 5px black;
    -webkit-box-shadow: 0 0 5px black;
    box-shadow: 0 0 5px black;
    z-index:1;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

琴流音 2024-11-08 08:08:00

好的,我看了一下,有好消息也有坏消息;)

#head div 中的不透明度过滤器意味着 overflow:hidden 正在被触发,这就是为什么没有菜单的原因(我担心这是过滤器和溢出的不幸副作用)..删除它,你就可以拥有你接下来需要的 z-index

以获得下拉菜单的透明度(不透明度),你可以使用 rgba (255,255,255,0.9) 在 #nav ul li ul 规则上,而不是 #fff; (尽管在该规则之前保留 #fff 以便为还不能执行 rgba() 的浏览器提供后备。阅读更多内容!)

这几乎是每个人都高兴的 - 现在您也可以使用渐变过滤器为 IE 做 rgba() 透明度..

所以我得到的规则看起来像这样(在 IE 条件注释中):

#nav ul li ul {
  zoom: 1;
  background: transparent;
  -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#E5FFFFFF,endColorstr=#E5FFFFFF)"; /* IE8 */    
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#E5FFFFFF,endColorstr=#E5FFFFFF);   /* IE6 & 7 */    
/*  behavior: url(PIE.htc);*/ /* yuk filter */  
}

我认为这是很好的..

<强>但是坏消息

该行为被注释掉了,因为你只能有一个或另一个,透明度或圆角,:(显然

我没有做太多研究,所以 YMMV

我也注意到一个问题或IE7 中的三个,不确定您是否想支持它,但如果您这样做..或者想检查我的最终代码,它到达了这个阶段,我将其粘贴在 PasteBin

该代码替换了您的主要 CSS - #head 规则和整个 /*navigation*/ 部分< /code>


更新:更多好消息和一点坏消息!

由于 CSS3 PIE 自己的 -pie-background 属性,您可以拥有透明度和圆角,也不是盒子阴影,PIE处理盒子阴影的方式意味着它填充div而不是仅仅在外面绘制,所以-pie-background rgba 背景的读取是透明的,但显示用于阴影的灰色!

我的解决方案:

我添加了一个边框来弥补盒阴影的损失,它看起来还不错,并且它可以在 IE 上运行;)
这是上面 I 条件评论的更新:

<!--[if lte IE 9]>
<style type="text/css" media="screen">
#nav ul li ul  {
    box-shadow: none; 
    -pie-background: rgba(255,255,255,0.9);
    border: 3px double #eee;
    border-width: 0 3px 3px 3px; 
    behavior: url(PIE.htc); /* yuk filter */
}
</style>
<![endif]-->

OK so I had a look and there's good news and bad ;)

the opacity filter in the #head div means that overflow: hidden is being triggered, which is why no menus (it's the unfortunate side effect of filters and overflow I'm afraid).. remove that and you can have your z-index which you need anyway

next to get the transparency (opacity) for your dropdowns you can just use rgba(255,255,255,0.9) on the #nav ul li ul rule instead of #fff; (though leave #fff before that rule for fallback for browsers that can't do rgba() yet.. read more!)

That's nearly everyone happy - now you can also do rgba() transparency for IE using the gradient filter..

so the rule I landed up with looked like this (in an IE conditional comment):

#nav ul li ul {
  zoom: 1;
  background: transparent;
  -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#E5FFFFFF,endColorstr=#E5FFFFFF)"; /* IE8 */    
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#E5FFFFFF,endColorstr=#E5FFFFFF);   /* IE6 & 7 */    
/*  behavior: url(PIE.htc);*/ /* yuk filter */  
}

and I thought it would be good to go..

BUT the Bad News

the behavior is commented out because you can only have one or the other, transparency or rounded corners, :( apparently

I didn't do too much research though so YMMV

I also noticed a problem or three in IE7, not sure if you want to support that but in case you do.. or want to check my final code which got it to this stage I pasted it in PasteBin

that code replaces your main CSS - the #head rule and whole /*navigation*/ section


Update: more good news and a little bad!

you can have the transparency and the rounded corners thanks to CSS3 PIE's own -pie-background property, but not the box shadow as well, the way PIE deals with box shadow means it fills the div instead of just drawing on the outside so the -pie-background reading of the rgba background is transparent but shows the grey color used for the shadow!

My solution:

I added a border to make up for loss of box-shadow, it's not looking too bad, and it's working across IE's ;)
here's an update to the I conditional comment above:

<!--[if lte IE 9]>
<style type="text/css" media="screen">
#nav ul li ul  {
    box-shadow: none; 
    -pie-background: rgba(255,255,255,0.9);
    border: 3px double #eee;
    border-width: 0 3px 3px 3px; 
    behavior: url(PIE.htc); /* yuk filter */
}
</style>
<![endif]-->
生生漫 2024-11-08 08:08:00

我不确定您使用的是哪个版本的 IE,但我在 IE6 和 IE7 中尝试过,菜单系统完全损坏。我这里没有 IE8、9 或 10 来测试,但我还是会猜测一个解决方案!

如果您还将 z-indexposition 添加到 #container 中,它应该可以解决您的问题。 z-index 仅适用于定位元素。

#container {
    position:relative;
    z-index:0;
}

还值得一读重叠和 z-index,它总结了属性并描述了使用 z-index 和 IE 时出现问题。

编辑:哇,直到我发现一台装有 IE8 的机器时我才意识到出了什么问题。我认为您稍微误解了标准CSSIE特定CSS原理。 IE 特定的 CSS 文件应该包含与标准文件不同的属性。您的 ie-style.css 文件包含所有规则的重复项,并且包含在所有版本的 IE 中。 IE8 比 IE6/7 更符合标准,您几乎不需要覆盖该版本的 CSS。

因此 IE 将应用相同样式的多个副本。在正常情况下,大多数浏览器都可以处理这种重复,但重复之一是 IE 特定的 filter 属性。

您在 style.cssie-style.css 中都有 filter:alpha(opacity=93);,即使它实际上应该只属于在 IE6/7 CSS 文件中为 IE8 过滤器的工作方式有所不同。如果您从两个样式表中删除过滤器,则菜单会在 IE8 中正确显示。

如果您需要在 IE6 或 IE7 中使用不透明度,我建议为这些浏览器创建一个特定的 CSS 文件,并使用条件注释仅将其包含在这些版本中。

I am not sure which version of IE you are having a problem with but I tried in IE6 and IE7 and the menu system is completely broken. I don't have IE8, 9 or 10 here to test but I'll take a guess at a solution nonetheless!

If you add a z-index and position to the #container as well, it should solve your problem. z-index only applies to positioned elements.

#container {
    position:relative;
    z-index:0;
}

It is also worth reading Overlapping and z-index, which summarises the properties and also describes the problems when using z-index and IE.

Edit: Wow, I did not realise what was wrong until I found a machine with IE8 on it. I think you have misunderstood the standard CSS and IE specific CSS principle slightly. The IE specific CSS file(s) should only contain the properties that are different to the standard ones. Your ie-style.css file contains duplicates of all the rules and is being included for all versions of IE. IE8 is much more standards compliant than IE6/7 and you should rarely have to override CSS for that version.

So IE will have multiple copies of the same style being applied. Under normal circumstances most browsers can cope with this duplication, however one of the duplicates is the IE specific filter property.

You have filter:alpha(opacity=93); in both style.css and ie-style.css even though it should really only belong in an IE6/7 CSS file as IE8 filters work differently. If you remove the filter from both stylesheets then the menu correctly displays in IE8.

If you need the opacity to work in IE6 or IE7, I suggest creating a specific CSS file for those browsers and using conditional comments to include it just for those versions.

蓝咒 2024-11-08 08:08:00

看看这个解决方案: http://webdemar.com /webdesign/superfish-jquery-menu-ie-z-index-bug/

我已经使用的另一个解决方案非常简单,但是*很痛苦。您必须为所有父容器指定一个比您想要显示在其他容器之上的 z-index 值更低的特定 z-index 值。

就像这样:

<parent>//z-index 1
    <child>//zindex 2
         <yourdropdown>//z-index3

更新 1

菜单在我的 chrome 中无法正确显示,因此我将 #head z-index 修复为 80,效果好多了。执行以下操作以使 IE、Chrome 和 Firefox 中的布局相同。但请注意,我只在主页上测试了这些更改。

将其添加到 .conbox 类中:

.conbox  {
position:relative;
}

正确放置徽标

#logo {
position:absolute;
left:0px;
top:0px;
}

删除 #nav 定位

#nav  {
margin-top:80px;
z-index:3;
}

问题是,我什至看不到 IE 中菜单鼠标悬停有任何效果!

Have a look at this solution : http://webdemar.com/webdesign/superfish-jquery-menu-ie-z-index-bug/

Another solution that I used already is quite easy, but a pain in the *. You must all the parent container a specific lower z-index value than the one you want to show on top of the others.

Like so :

<parent>//z-index 1
    <child>//zindex 2
         <yourdropdown>//z-index3

Update 1

The menu didn't show correctly in my chrome so I fixed the #head z-index to 80 and it did way better. Do the following to get the layout the same in IE and Chrome and Firefox. Watch out though, I only tested those change on the homepage.

Add this to the .conbox class :

.conbox  {
position:relative;
}

Place the logo correctly

#logo {
position:absolute;
left:0px;
top:0px;
}

Remove the #nav positioning

#nav  {
margin-top:80px;
z-index:3;
}

The problem is, I can't even see any effect on the menu mouseover in IE!!

っ左 2024-11-08 08:08:00

为菜单覆盖的元素设置 z-index: -1 和 men div 的 z 索引为我解决了这个问题。
#bodyWrapper
{
背景:无重复滚动 0 0 #E4F7FE;
溢出:隐藏;
位置:相对;
宽度:100%;
内边距:0 0 60px;
z 索引:-1;
}

Setting z-index: -1 for elements that menu overlays and z index of men div resolved this problem for me.
#bodyWrapper
{
background: none repeat scroll 0 0 #E4F7FE;
overflow: hidden;
position: relative;
width: 100%;
padding: 0 0 60px;
z-index: -1;
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文