怎样定义CSS使PNG透明图片在IE6中透明?
- 提问者网友:嗝是迷路的屁
- 2021-05-02 07:11
- 五星知识达人网友:刀戟声无边
- 2021-05-02 08:45
这个需要用到JS
首先,打开Dreamweaver,新建一个JavaScript基本页,并复制以下代码替换掉里面的代码,完成后保存为png.js文件
// Correctly handle PNG transparency in Win IE 5.5 or higher.
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
+ " " + "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
}
}
}
window.attachEvent("onload", correctPNG);
然后打开你要使PNG透明的页面,在<head>区内插入下面代码,注意一下地址就可以了
<script type="text/javascript" src="png.js"></script>
- 1楼网友:荒野風
- 2021-05-02 09:29
呵呵,自己能解决问题那是再好不过的事情