如何在IE6中修复背景图片的PNG透明度错误?
发布于 2009-03-30 07:40:25
我喜欢David Cilley不久前写的这个Javascript解决方案。它摆脱了兼容浏览器的障碍,可以与任何你想要的后端一起使用。不过,它仍然需要一个空白的gif图像。
将这些函数添加到您的HTML头或其他现有.js中,包括:
<script type="text/javascript">
function fixPngs(){
// Loops through all img tags
for (i = 0; i < document.images.length; i++){
var s = document.images[i].src;
if (s.indexOf('.png') > 0) // Checks for the .png extension
fixPng(s, document.images[i]);
}
}
function fixPng(u, o){
// u = url of the image
// o = image object
o.src = 'images/spacer.gif'; // Need to give it an image so we don't get the red x
o.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + u + "', sizingMethod='scale')";
}
</script>
将以下条件注释放在底部(页脚部分,就在前面):
<!--[if lte IE 6]>
<script language="javascript" type="text/javascript">
//this is a conditional comment that only IE understands. If a user using IE 6 or lower
//views this page, the following code will run. Otherwise, it will appear commented out.
//it goes after the body tag so it can fire after the page loads.
fixPngs();
</script>
<![endif]-->
要获得更全面的解决IE6问题的方法,请尝试IE7 Javascript library。
发布于 2009-03-30 07:25:57
使用这个:http://www.twinhelix.com/css/iepngfix/
这也适用于IE 5.5,但不适用于mac版本的IE或更早版本的IE。
我在相当少的网站上使用过它,并且没有遇到任何问题。
但是,在脚本生效之前,PNG周围有时会出现一个丑陋的灰色方框。
发布于 2009-03-30 07:35:32
ie6.css:
img {
behavior: url("pngbehavior.htc");
}
page.html:
<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="ie6.css" />
<![endif]-->
https://stackoverflow.com/questions/697682
复制相似问题