IE8,透明PNG和滤镜:alpha
我就切入正题吧。这是输出:
(现在是一些可选代码 - 仅在您确实想要时才读取;))
这是标记:
<a href="/" id="logo_wrapper">
<span class="logo logo_normal"></span>
<span class="logo logo_hover"></span>
</a>
这是 CSS(仅缩短为相关内容,以方便您阅读):
#logo_wrapper {
position:relative;
}
#logo_wrapper .logo {
display:block;
width:260px;
height:80px;
background-image:url(logo.png);
position:absolute;
}
#logo_wrapper .logo_normal {
background-position:0 0;
}
#logo_wrapper .logo_normal:hover {
opacity:0;
filter:alpha(opacity=0);
}
#logo_wrapper .logo_hover {
background-position:0 -80px;
opacity:0;
filter:alpha(opacity=0);
}
#logo_wrapper .logo_hover:hover {
opacity:1;
filter:alpha(opacity=100); /* THIS IS THE OFFENDER! */
}
只是为了澄清:我知道我可以使用单个 span
并只需切换徽标的 悬停时的背景位置
,但完整的 CSS 具有可爱的 CSS3 过渡,适用于不应该上下滚动徽标的真实浏览器。
好的,这是一个具有 32 位颜色深度和透明度的 PNG。当我根本不使用 alpha 过滤器或 filter:alpha(opacity=0)
时,在 IE8 中一切都很好。但当不透明度设置为 100 时,仅仅使用滤镜就会导致 IE8 变得疯狂,使所有不完全透明的像素变成 100% 不透明。并不是说这个特定的图像在这种效果下看起来那么糟糕,但它仍然很烦人:D。
现在,我很清楚 IE8 因透明 PNG 问题而臭名昭著,这些问题可以追溯到 IE6 及其透明区域的丑陋的纯青色填充。这个问题可以通过一些 IE 行为黑魔法来修复。
IE8可以做什么?
I'll cut right to the point. Here's the output:
(now some optional code - read only if you really want to ;))
Here's the markup:
<a href="/" id="logo_wrapper">
<span class="logo logo_normal"></span>
<span class="logo logo_hover"></span>
</a>
Here's the CSS (shortened only to the relevant stuff, for your reading pleasure):
#logo_wrapper {
position:relative;
}
#logo_wrapper .logo {
display:block;
width:260px;
height:80px;
background-image:url(logo.png);
position:absolute;
}
#logo_wrapper .logo_normal {
background-position:0 0;
}
#logo_wrapper .logo_normal:hover {
opacity:0;
filter:alpha(opacity=0);
}
#logo_wrapper .logo_hover {
background-position:0 -80px;
opacity:0;
filter:alpha(opacity=0);
}
#logo_wrapper .logo_hover:hover {
opacity:1;
filter:alpha(opacity=100); /* THIS IS THE OFFENDER! */
}
Just to clarify: I'm aware I can get away with a single span
and just switching the logo's background-position
on hover, but the full CSS features cute CSS3 transitions for real browsers that aren't supposed to scroll the logo up and down.
OK, so, it's a PNG with 32 bit colour depth and, of course, transparency. All is fine in IE8 when I use no alpha filter at all or filter:alpha(opacity=0)
. But with the opacity set to 100, the mere use of the filter causes IE8 to go crazy and make all not entirely transparent pixels 100% opaque. Not that this particular image looks all that bad with this effect, but it's still annoying :D.
Now, I'm well aware IE8 is notorious for transparent PNG problems, with the troubles dating back to IE6 and its hideous solid cyan fill of the transparent areas. That one could be fixed with some IE behaviour black magic.
What can be done about IE8?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
一个简单的修复:只需向 .logo_hover:hover 添加背景颜色,Alpha 过滤器就会再次正常工作。
显然,此修复并不总是有用(也就是说,如果您不能在 png 下面使用模仿真实背景的背景颜色)。
A simple fix: just add a background color to .logo_hover:hover and alpha filter works fine again.
Obviously this fix is not always useful (that is, if you can't use a background color below your png that mimics the real background).
您需要使用
AlphaImageLoader
过滤器,就像 IE6 一样。You need to use the
AlphaImageLoader
filter, just like for IE6.这对我有用:
谢谢 SLAks!
This worked for me:
Thanks SLaks!!
在
:hover
类中使用filter:none
。Use
filter:none
in your:hover
class.