IE6 PNG透明度

Jak*_*old 24 internet-explorer png transparency internet-explorer-6

如何在IE6中修复背景图像中的PNG透明度错误?

Rob*_*len 20

我喜欢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>
Run Code Online (Sandbox Code Playgroud)

将以下条件注释放在底部(页脚部分,就在</ body>之前):

<!--[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]-->
Run Code Online (Sandbox Code Playgroud)

有关IE6奇怪的更全面的方法,请尝试IE7 Javascript库.


Tim*_*ers 8

使用此:http: //www.twinhelix.com/css/iepngfix/

这对IE 5.5也有好处,但不适用于IE的IE版本或早期版本的IE.

我在很少的网站上使用它并且没有任何问题.

然而,在剧本开始之前,PNG周围有时会出现一个丑陋的灰色框.


var*_*tec 8

使用PNG行为.

ie6.css:

img {
   behavior: url("pngbehavior.htc");
}
Run Code Online (Sandbox Code Playgroud)

page.html中:

<!--[if IE 6]> 
  <link rel="stylesheet" type="text/css" href="ie6.css" />
<![endif]-->
Run Code Online (Sandbox Code Playgroud)