IE6不支持PNG半透明图片的缺陷为web设计带来了极大的不便,很多人用滤镜+hack的方法实现显示PNG,不过实现起来相当繁琐。还有一种网上比较流行的方法,更加简便,下面详细介绍这种方法:
2010410更新
最近在网上找到了一个比较方便,也可以实现png透明背景平铺的一个方法,一起来看看吧。
1、将iepngfix.htc和blank.gif两个文件放入站点内;
下载文件 (已下载 177 次)
2、在样式表中加入如下代码
程序代码
img, div {
behavior: url(/htc/iepngfix.htc);
}
把以下代码保存为correctpng.js
function correctPNG()
{
for(var i=0; i<document.images.length; i++)
{
var img = document.images[i]
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
i = i-1
};
};
};
if(navigator.userAgent.indexOf("MSIE")>-1)
{
window.attachEvent("onload", correctPNG);
};
在网页的头部引用一下
使用的时候直接用img标签即可。
2010410更新
最近在网上找到了一个比较方便,也可以实现png透明背景平铺的一个方法,一起来看看吧。
1、将iepngfix.htc和blank.gif两个文件放入站点内;
下载文件 (已下载 177 次)2、在样式表中加入如下代码
程序代码
img, div {
behavior: url(/htc/iepngfix.htc);
}
把以下代码保存为correctpng.js
function correctPNG()
{
for(var i=0; i<document.images.length; i++)
{
var img = document.images[i]
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
i = i-1
};
};
};
if(navigator.userAgent.indexOf("MSIE")>-1)
{
window.attachEvent("onload", correctPNG);
};
在网页的头部引用一下
<SCRIPT language=JavaScript src="correctpng.js" type=text/javascript></SCRIPT>
使用的时候直接用img标签即可。
tommyhu.cn网友
2011/12/20 02:05
天空中最美的是星空,人需要什么
tommyhu.cn网友
2010/05/20 09:56
我怎么试了不行了
tommyhu 回复于 2010/05/21 17:55
其实环境都是挺复杂的,我很久前试的
分页: 1/1
1
1
DIV+CSS命名规则
css3.0参考手册.chm


2009/11/17 20:37 | by 
tommyhu:
