解决IE6不支持PNG-24透明的问题

IE6 png 透明 (三种解决方法)(转来的哦)

FF和IE7已经直接支持透明的png图了,下面这个主要是解决IE6下透明PNG图片有灰底的

=============================================================================

此效果简单,。。。。相当不错 推荐

style="FILTER: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=images/fl.png‘)"

语法:

filter : progid:DXImageTransform.Microsoft.AlphaImageLoader ( enabled=bEnabled , sizingMethod=sSize , src=sURL )

enabled : 可选项。布尔值(Boolean)。设置或检索滤镜是否激活。true | false true : 默认值。滤镜激活。

false : 滤镜被禁止。

sizingMethod : 可选项。字符串(String)。设置或检索滤镜作用的对象的图片在对象容器边界内的显示方式。 crop : 剪切图片以适应对象尺寸。

image : 默认值。增大或减小对象的尺寸边界以适应图片的尺寸。

scale : 缩放图片以适应对象的尺寸边界。

src : 必选项。字符串(String)。使用绝对或相对 url 地址指定背景图像。假如忽略此参数,滤镜将不会作用。

特性:

Enabled : 可读写。布尔值(Boolean)。参阅 enabled 属性。

sizingMethod : 可读写。字符串(String)。参阅 sizingMethod 属性。

src : 可读写。字符串(String)。参阅 src 属性。

说明:

在对象容器边界内,在对象的背景和内容之间显示一张图片。并提供对此图片的剪切和改变尺寸的操作。如果载入的是PNG(Portable Network Graphics)格式,则0%-100%的透明度也被提供。

PNG(Portable Network Graphics)格式的图片的透明度不妨碍你选择文本。也就是说,你可以选择显示在PNG(Portable Network Graphics)格式的图片完全透明区域后面的内容。

实例:解决IE6下png透明失效的问题。

CSS样式:

.png{

_background: url(http://www.snowangel.cn/images/angel.png) no-repeat !important;

filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=noscale, src="http://www.snowangel.cn/images/angel.png");

background:none;

width:118px;height:133px;

}

.png div{position:relative;}

HTML代码:

<div class="png">

<div>

CSS 背景PNG透明 及 链接失效问题解决

</div>

</div>

=============================================================================

第 1 种方法:定义一个样式,给某个div应用这个样式后,div的透明png背景图片自动透明了。(注意两处图片的路径写法不一样,本例中,icon_home.png图片与html文件在相同目录)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>无标题文档</title>

<style type="text/css">

<!--

.qq {

height: 90px;

width: 90px;

background-image: url(icon_home.png)!important;

background-repeat: no-repeat;

_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=‘icon_home.png‘);

_ background-image: none;

}

-->

</style>

</head>

<body>

<div class="qq"></div>

</body>

</html>

第 2 种方法: 给img定义样式,页面上所有透明png即自动透明了。(这方法只对直接插入的图片有效,对背景图无效)注意,要准备一个透明的小图片transparent.gif,大小不限。必须放在和html相同的目录

请勿大量使用,否则会导致页面打开很慢!!!)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>无标题文档</title>

<style type="text/css">

.mypng 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>

</head>

<body>

换成你的png图片

<div class="mypng">

<img src="icon_face_07.png" width="30" height="30" />

<img src="icon_face_10.png" width="30" height="30" />

<img src="icon_face_08.png" width="30" height="30" />

</div>

</body>

</html>

第 3 种方法:用JS实现,加上一段js代码后,所有插入的透明png自动透明了.(注意,这方法也是只对直接插入的图片有效,对背景图无效)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>无标题文档</title>

<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 type="text/css">

<!--

body {

background-color: #9999CC;

}

-->

</style></head>

<body>

把图片换成你自己的图片

<img src="img/icon_face_03.png" width="30" height="30" /><!--把图片换成你自己的图片 -->

<img src="img/icon_face_05.png" width="30" height="30" />

<img src="img/menu_title_over.png" width="130" height="36" />

</body>

</html>

方法四

<script language="javascript">

// 修复 IE 下 PNG 图片不能透明显示的问题

function fixPNG(myImage) {

var arVersion = navigator.appVersion.split("MSIE");

var version = parseFloat(arVersion[1]);

if ((version >= 5.5) && (version < 7) && (document.body.filters))

{

var imgID = (myImage.id) ? "id=‘" + myImage.id + "‘ " : "";

var imgClass = (myImage.className) ? "class=‘" + myImage.className + "‘ " : "";

var imgTitle = (myImage.title) ? "title=‘" + myImage.title   + "‘ " : "title=‘" + myImage.alt + "‘ ";

var imgStyle = "display:inline-block;" + myImage.style.cssText;

var strNewHTML = "<span " + imgID + imgClass + imgTitle

+ " style=\"" + "width:" + myImage.width

+ "px; height:" + myImage.height

+ "px;" + imgStyle + ";"

+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"

+ "(src=\‘" + myImage.src + "\‘, sizingMethod=‘scale‘);\"></span>";

myImage.outerHTML = strNewHTML;

} }

window.onload=function(){

document.getElementByIdx("top").style.height=screen.height/5+"px";

}//

</script>

用法如下:

<img src="logo.png" width="328" height="325" border="0" />

时间: 2024-08-25 11:28:32

解决IE6不支持PNG-24透明的问题的相关文章

两种解决IE6不支持固定定位的方法

有两种让IE6支持position:fixed1.用CSS执行表达式 *{margin:0;padding:0;} * html,* html body{ background-image:url(about:blank); background-attachment:fixed; } * html .fixed{ position:absolute; bottom:auto; top:expression(eval(document.documentElement.scrollTop+ doc

解决IE6不支持position:fixed属性

最近在优化网站浮动广告时候遇见了IE6不支持position:fixed属性.上网收集了一下解决方案 比较好的方案就是利用css表达式进行解决 补充:CSS Expression (CSS 表达式),是一种使用动态设置 CSS 属性的方式,并且被 IE5 以上的版本所支持,但是 IE8 的标准模式已不再支持 CSS 表达式了 IE7和以上的浏览器都支持position:fixed: 之前写过一篇介绍过固定页脚的文字,那时候没在ie6下测试 方法一 <!--[if IE 6]> <styl

DD_belatedPNG解决IE6不支持PNG透明图片绝佳方案

引入js文件,同样由于此js只有使用IE6时才有用,所以为了让我们的页面更加高效的执行,页面中插入一段只有IE6的时候才调用执行此JavaScript即可: 1 <!--[if IE 6]> 2 <script type="text/javascript" src="../script/DD_belatedPNG_0.0.8a-min.js"></script> 3 <script type="text/javas

DD_belatedPNG,解决 IE6 不支持 PNG-24 绝佳解决方案

png24在ie下支持透明.终于找到下面的可行办法: 我们知道 IE6 是不支持透明的 PNG-24 的,这无疑限制了网页设计的发挥空间. 然而整个互联网上解决这个 IE6 的透明 PNG-24 的方案也是多不胜数,从使用 IE 特有的滤镜或是使用透明 GIF 替代.但是这些方法都有一个缺点,就是不支持 CSS 中 backgrond-position 与 background-repeat . 而我今天介绍 DD_belatedPNG ,只需要一个理由,就是它支持 backgrond-posi

解决IE6不支持position:fixed固定定位的bug(转载范鸭)

http://blog.funya.in/csscss3/ie6-fixed-bug/ 在IE6中实现 position:fixed; 的办法: 浏览器头部固定 .fixed_top { position:fixed; top:0px; } * html .fixed_top /* IE6 头部固定 */{ position:absolute; bottom:auto; top:expression(eval(document.documentElement.scrollTop)); } 浏览器

完美解决IE6不支持position:fixed的bug【转】

废话不多说,先看一下下面这段代码: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>IE6 position:fixed bug</title> <style> *{padding:0;margin:0} p{heigh

解决IE6不支持position:fixed的Bug

/* 除IE6浏览器的通用方法 */ .ie6fixedTL{position:fixed;left:0;top:0} .ie6fixedBR{position:fixed;right:0;bottom:0} /* IE6浏览器的特有方法 */ /* 修正IE6振动bug */ * html,* html body{background-image:url(about:blank);background-attachment:fixed} * html .ie6fixedTL{position:

IE6不支持first-child的解决方法

乌龙猫网站昨日刚刚上线,后来在IE6下发现侧边栏的智能浮动中,第一个模块的margin-top不为0,这个原本在CSS中已经定义的样式为: HTML: <div class="sidebar_block"></div> CSS: .sidebar_block:first-child { margin:0; } 遇到IE6不支持first-child伪类不是第一次了,平时都是用jquery解决,只要用一句:$(.sidebar_block:first).css()

IE6下png背景不透明——张鑫旭博客读书笔记

从今天开始跟着大牛张鑫旭的步伐,每天进步一点点 问题:IE6不支持png背景透明或半透明 一.可解决的方法 补充:css滤镜主要是用来实现图像的各种特殊效果.(了解) css滤镜的标识符是"filter",总体的应用上和其他的css语句相同.css滤镜可分为基本滤镜和高级滤镜两种.css滤镜分类 CSS滤镜 可以直接作用于对象上,并且立即生效的滤镜称为基本滤镜.而要配合JavaScript等脚本语言,能产生更多变幻效果的则称为高级滤镜. 只有IE可以完全的支持滤镜,Firefox支持部