css代码
Internet Explorer中提供了提供了独有的滤镜效果,他通过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)格式的图片完全透明区域后面的内容。
* html div { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src="tran.png"); background:none; }
注意:这里我们使用了 “*”的CSS hack,这个CSS Hack是Internet Explorer 6独有的,在Ineternet Explorer 6的DOM结构中,默认HTML的父节点为*,而在标准的DOM结构中HTML就是根节点。所以上面的CSS 规则只有Internet Explorer 6 认识。
png的图层会导致上面链接失效
要在用到滤镜filter内的a链接样式上加上position:relative;
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>
_background 是IE6的hank 属性, 在样式属性前加“ _ ” 只有ie6能识别.
js代码
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 } } } } if (window.addEventListener) window.addEventListener("load", correctPNG, false) else if (window.attachEvent) window.attachEvent("onload", correctPNG)
让“块”透明的方法
测试IE6,IE7,IE8,FF2,FF3均通过。提示:IE6,IE7需设置一个宽度(100%也行),否则看不到效果。
但 FireFox 3.5+ 已不再支持 -moz-opacity
于是要设置一下透明度为60%的DIV就应该这样写了:
div.transp { /* make the div translucent */
opacity: 0.6; /* Firefox, Safari(WebKit), Opera)
filter: "alpha(opacity=60)"; /* IE 8 */
filter: alpha(opacity=60); /* IE 4-7 */
zoom: 1; /* needed in IE up to version 7, or set width or height to trigger "hasLayout" */
}
opacity这个是属于CSS3里面的东西了,属于CSS3的标准。然而微软IE8还不支持这一属性。
DIV背景半透明,DIV中的字不半透明
<body bgcolor="#336699">
<div style="filter:alpha(opacity=50);background:#ffffff;width:600;"><span style="color:yellow">图层背景半透明,字体颜色也半透明</span></div>
<div style="filter:alpha(opacity=50);background:#ffffff;width:600">< span style="position:relative;color:yellow">图层背景半透明,字体颜色不半透明</span>& lt;/div>
文章从网络上整理,如果有侵权请通知!