PNG图在IE6下透明的终极解决方案

现在做很多页面,比如阴影,或很多情况要用到透明图,GIF图一般会有很多锯齿,
用PNG图吧,效果到是还好。Firefox和IE7以上版本都 支持PNG透明,但IE6缺会显示灰白。
百度,google搜罗一通,现总结如下两种。如有更好的方案,望交流

第一种,适用于图片做背景的时候。 代码:

 

<style>
	body {
			background: url(body-bg.jpg); /* 添加基本背景图 */
	}
	.vehicles {
			width: 500px;
			height: 176px;
			background: url(vehicles.png) no-repeat; /* 为vehicles类添加背景图 */
	}

    /* 注:我在vehicles类名前添加了”html”, 我这样做就不会使background属性与另一个样式表冲突了. */
    html .vehicles {
            background: none; /* 隐藏当前背景图从而使用后面的滤镜重置它 */
            width: 500px; /* 必须指定宽度 */
            height: 176px; /* 必须指定高度 */
            filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='vehicles.png');
    }


</style>
<div class=”vehicles”></div>
 


第二 种,适用于PNG图片放在页面上的时候

/*-------------IE6-PNG透明 ------------------------*/
* html img,
* html .png{
    behavior: e­xpression((this.runtimeStyle.behavior="none")&&(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 = "images/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)
        
    );
}
/*-------------------------------------------------------------------------*/
 


下面是源代码

下载文件png透明图FOR-IE6.rar

---------------------------------------------------------------------------------------

 


第三种解决方案


附上DEMO。有需要可以下载看看。

下载文件PNG-ie6-透明

 

 

我一般采用后两个方案的结合,一个是用在页面中的图片,一个用在容器背景中的图片。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值