低版本IE支持透明png格式图片的方法。png作为图片插入:在这里下载 pngfix.js ,在页面head加入
<!--[if lt IE 7.]>
<script defer type="text/javascript" src="pngfix.js"></script>
<![endif]-->
单页面可以直接加入
<!--[if lt IE 7]>
<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>
<![endif]-->
png图片作为背景:
让ie6支持透明的一种方法:
<!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>让IE支持透明的PNG图片</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-color:#000000;
}
#s{
position:relative;
cursor:move;
width:1280px;
height:800px;
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale', src='********.png');
}
*>
#s {
background:url("*******.png")
}
/*FIREFOX*/
-->
</style>
</head>
<body>
<div id="s" ></div>
</body>
</html>
要注意的是图片路径要相对于页面,如果这些滤镜样式写在css里,要注意这个问题,还有,一旦用了png做背景以后,以png为背景的元素内,链接a就失去了焦点,这个问题,通过在a的外部增加一个新的盒子,给盒子一个position为相对就可以解决,呵呵,说到底,这些方法都很麻烦,所以图片如果能切成gif透明,就不要用png的透明了
相关资源:css 半透明 让IE6支持png图片半透明解决方法