首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IE6 PNG透明度

IE6 PNG透明度
EN

Stack Overflow用户
提问于 2009-03-30 15:24:28
回答 12查看 11.4K关注 0票数 24

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

EN

回答 12

Stack Overflow用户

回答已采纳

发布于 2009-03-30 15:40:25

我喜欢David Cilley不久前写的这个Javascript解决方案。它摆脱了兼容浏览器的障碍,可以与任何你想要的后端一起使用。不过,它仍然需要一个空白的gif图像。

将这些函数添加到您的HTML头或其他现有.js中,包括:

代码语言:javascript
复制
<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>

将以下条件注释放在底部(页脚部分,就在前面):

代码语言:javascript
复制
<!--[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

票数 20
EN

Stack Overflow用户

发布于 2009-03-30 15:25:57

使用这个:http://www.twinhelix.com/css/iepngfix/

这也适用于IE 5.5,但不适用于mac版本的IE或更早版本的IE。

我在相当少的网站上使用过它,并且没有遇到任何问题。

但是,在脚本生效之前,PNG周围有时会出现一个丑陋的灰色方框。

票数 8
EN

Stack Overflow用户

发布于 2009-03-30 15:35:32

使用PNG Behaviour

ie6.css:

代码语言:javascript
复制
img {
   behavior: url("pngbehavior.htc");
}

page.html:

代码语言:javascript
复制
<!--[if IE 6]> 
  <link rel="stylesheet" type="text/css" href="ie6.css" />
<![endif]-->
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/697682

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档