虽然说现在早就不用ie6浏览器了,可以还是有一小部分还在使用 ,刚好公司也有要求~~~

<p>     E6不兼容png图片,确实让网页的图片质量大大下降,为了兼容万恶的IE6,总结了下面几种方法:
1,通过CSS滤镜使背景图的PNG对IE6进行兼容。
2,给img定义样式,页面上所有透明png即自动透明了。
3,通过JS,插入一段代码,实现img标签png兼容IE6的问题。
4,可以把png图片,转换为gif图片。(最简单常用的方法)
</p>
第一种方法:

    1、通过CSS滤镜使背景图的PNG对IE6进行兼容
定义一个样式,给某个div应用这个样式后,div的透明png背景图片自动透明了。
 <style>
body{background: lightblue;}
.png{
width: 550px;
height: 500px;
background-image: url(pic.png)!important;/* FF IE7 */
background-repeat: no-repeat;
_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='pic.png'); /*IE6*/
_ background-image: none; /* IE6 */
overflow: hidden;
}
</style>
<div class="png">
<div>通过CSS滤镜使背景图的PNG对IE6进行兼容</div>
</div>

第二种方法
    给img定义样式,页面上所有透明png即自动透明了。注意:这方法只对直接插入的图片有效,对背景图无效。
要准备一个透明的小图片transparent.gif,大小不限,并将gif的图片放在跟png图片一个文件夹里。请勿大量
使用,否则会导致页面打开很慢!!!不过这种方法设置图片的不能控制其大小。
 <style>
body{background: lightblue;}
.imgpng img {
azimuth: expression(
this.pngSet?this.pngSet=true:(this.nodeName == "IMG" && this.src.toLowerCase().indexOf('.png')>-1?(this.runtimeStyle.backgroundImage = "none",
this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "', sizingMethod='image')",
this.src = "transparent.gif"):(this.origBg = this.origBg? this.origBg :this.currentStyle.backgroundImage.toString().replace('url("','').replace('")',''),
this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.origBg + "', sizingMethod='crop')",
this.runtimeStyle.backgroundImage = "none")),this.pngSet=true); }
</style>

<div class="imgpng">
<img src="pic.png" />
</div>

第三种方法:
通过JS,插入一段代码,实现img标签png兼容IE6的问题
 <script language="JavaScript">
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
if ((version >= 5.5) && (document.body.filters))
{
for(var j=0; j<document.images.length; j++)
{
var img = document.images[j]
var imgName = img.src.toUpperCase()
if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
{
var imgID = (img.id) ? "id='" + img.id + "' " : ""
var imgClass = (img.className) ? "class='" + img.className + "' " : ""
var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
var imgStyle = "display:inline-block;" + img.style.cssText
if (img.align == "left") imgStyle = "float:left;" + imgStyle
if (img.align == "right") imgStyle = "float:right;" + imgStyle
if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
var strNewHTML = "<span " + imgID + imgClass + imgTitle
+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
img.outerHTML = strNewHTML
j = j-1
}
}
}
}
window.attachEvent("onload", correctPNG);
</script>
 <style>
body{background: lightblue;}
div img{bottom: 3px solid yellow;}
</style> <div class="imgpng">
<img src="pic.png"/>
</div>

番外:

使用IE6的hack来书写只有IE6能识别的css样式。

 .bb{
height:32px;
background-color:#f1ee18;/*所有识别*/
.background-color:#00deff\9; /*IE6、7、8识别*/
+background-color:#a200ff;/*IE6、7识别*/
_background-color:#1e0bd1;/*IE6识别*/
}
于是大家还可以这样来区分firefox,IE7,IE6
background:green!important; *background:orange; _background:blue;

关于兼容ie6的一些方法:
背景png图片,括号里的是样式选择器,中间用逗号隔开

<!--[if IE 6]>
<script type="text/javascript" src="js/DD_belatedPNG.js"></script>
<script type="text/javascript">
DD_belatedPNG.fix('.tel,.head_content');
</script>
												

PNG兼容IE6解决方法的更多相关文章

  1. VMware workstation虚拟机配置文件不兼容无法使用解决方法

    VMware workstation虚拟机配置文件不兼容无法使用解决方法打开VMware workstation虚拟机提示:配置文件"--.vmx"是由Vmware产品创建,但该产 ...

  2. PNG24图片兼容IE6解决的方法

    非常多人都遇到一个问题:那就是PNG不能正常显示,比方: 网上试过的非常多办法都非常难实现.要嘛就是效果不好,那如今最好的办法就是直接调用JS插件,解决! 点击下载 如今说一下怎么用这个文件吧! 首先 ...

  3. Error:const char* 类型的实参和LPCWSTR类型的形参不兼容的解决方法。

    在C++的Windows 应用程序中经常碰到这种情况. 解决方法: 加入如下转换函数: LPCWSTR stringToLPCWSTR(std::string orig) { size_t origs ...

  4. 前端页面兼容ie8解决方法

    一.通用兼容文件的引用: 1.HTML5标签兼容方案:html5shiv.js GitHub地址:https://github.com/aFarkas/html5shiv/ IE8不支持HTML5的新 ...

  5. png兼容IE6的方法

    1.通过CSS滤镜使背景图的PNG对IE6进行兼容 定义一个样式,给某个div应用这个样式后,div的透明png背景图片自动透明了. <style> body{background: li ...

  6. !important的用法(IE6 兼容的解决方法)

    我们知道,CSS写在不同的地方有不同的优先级, .css文件中的定义 < 元素style中的属性,但是如果使用!important,事情就会变得不一样. 首先,先看下面一段代码: <!DO ...

  7. jq1.9.0以上版本不兼容live()解决方法

    最近一个项目里用bootstrap做图形渲染,需要用到jq1.9以上版本,而copy的js代码里用到了live()方法,故两者产生了兼容问题,下面是解决方案: $('#my').on("cl ...

  8. PNG图片透明 IE6 解决方法

    原文发布时间为:2009-11-18 -- 来源于本人的百度文章 [由搬家工具导入] png透明解决办法 第1 种方法:定义一个样式,给某个div应用这个样式后,div的透明png背景图片自动透明了。 ...

  9. IE7下对某些seajs压缩文件不兼容的解决方法

    seajs.config({ comboExcludes: /common.js/ }) (杨磊哥提供)

随机推荐

  1. java_redis3.0.3集群搭建

    redis3.0版本之后支持Cluster,具体介绍redis集群我就不多说,了解请看redis中文简介. 首先,直接访问redis.io官网,下载redis.tar.gz,现在版本3.0.3,我下面 ...

  2. Innode引擎监控的开启的方法

    查看当前InnoDB引擎信息 mysql> show innodb status\G 开启InnoDB监控,有四种: 1. innodb_monitor mysql> create tab ...

  3. Linux shell 脚本攻略之统计文件的行数、单词数和字符数

    摘自:<Linux shell 脚本攻略>

  4. Asp.Net 之 抓取网页内容

    一.获取网页内容——html ASP.NET 中抓取网页内容是非常方便的,而其中更是解决了 ASP 中困扰我们的编码问题. 需要三个类:WebRequest.WebResponse.StreamRea ...

  5. cocos2d-x lua 实现状态机

    cocos2d-x lua 实现状态机 version: cocos2d-x 3.6 0.状态机 状态机主要分为2大类:第一类,若输出只和状态有关而与输入无关,则称为Moore状态机:第二类,输出不仅 ...

  6. android 编写动画

    1.在编写动画的时候需要新建一个xml 新建的步骤是选中res单击右键选择Android resource file 然后弹出一个框 ,然后再Resource Type 里面选择Animation 然 ...

  7. 移动终端学习2:触屏原生js事件及重力感应

    如今智能移动设备已经渗透到人们生活的方方面面,用户数量也在不断迅速增长(市场研究机构 eMarketer 在今年初发表的趋势报告中预测,2014年至2018年,中国智能手机用户从总人口的 38.3%增 ...

  8. HDU 3533 Escape (BFS + 预处理)

    Escape Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  9. Eclipse NDK 配置,无需安装Cygwin

    Eclipse NDK 配置,不用安装Cygwin 文章转自http://www.cnblogs.com/chenjiajin/archive/2012/04/12/2444188.html 一.关于 ...

  10. Unity3D鼠标点击物体产生事件

    如果需要处理鼠标点击物体的情况, 可以当数据接触物体时,鼠标手势改变,然后点击后和NPC产生对话等: using UnityEngine; using System.Collections; publ ...