关于IE7半透明背景问题

透明度和半透明背景是我们在编辑前端页面时经常使用的CSS属性,但是这两个属性在IE8以下的IE浏览器却不兼容性。透明度我们都知道通过opacity:0.5;filter:alpha(opacity=50);

进行去兼容低版本的IE浏览器,但是对于半透明背景却没有比较实用的方法。

下面是关于半透明背景在低版本浏览器使用的一个小的总结,希望对大家有帮助!

1、通过filter:progid:DXImageTransform.Microsoft.Gradient(enabled=bEnabled,startColorStr=iWidth,endColorStr=iWidth)对低版本进行兼容。

首先介绍一下涉及到的几个参数:

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

true:默认值,滤镜被激活。

false:滤镜被禁止(filter将不起作用)。

startColorStr:可选项。字符串(String)。设置或检索色彩渐变的开始颜色和透明度。

其格式为#AARRGGBB。AA、RR、GG、BB为十六进制正整数。取值范围为00-FF。RR指红色值(red),GG指绿色值(green),BB指蓝色值(blue),参阅#RRGGBB颜色单位。AA指透明度。00是完全透明。FF是完全不透明。超出取值范围的值将被恢复为默认值。

取值范围#FF000000-#FFFFFFFF。默认值为#FF0000FF。不透明蓝色。

EndColorStr:可选项。字符串(String)。设置或检索色彩渐变的结束颜色和透明度。参阅 startColorStr 属性。默认值为 #FF000000 。不透明黑色。

GradientType:可读写。整数值(Integer)。设置或检索色彩渐变的方向。1 | 0。

1:默认值。水平渐变。

0:垂直渐变。

下面是一个具体的小例子(为以图片为背景为例):

html代码如下:

<div class="wrap">
			<div class="img-wrap img-wrap1">
				<img src="img/p2.jpg"/>
			</div>
		</div>


CSS代码:

.wrap{
position: relative;
width: 964px;
margin: 50px auto;
background:#333333 url(img/p1.jpg) no-repeat;
background-size: 100% 100%;
}
.img-wrap{
position: relative;
width: 100%;
height: 100%;
text-align: center;
font-size: 0px;
background: rgba(0,0,0,0.6);
}
.img-wrap .img{
position: relative;
z-index: 3;
}
.img-wrap1{
filter:progid:DXImageTransform.Microsoft.gradient(enabled=true, GradientType = 0,startColorstr = '#60000000',endColorstr = '#60000000');
}

IE7下运行效果如下:


2、可以通过设置透明度设置半透明背景,这是html布局上就会有一点不同,具体如下:

html代码:

<div class="wrap">
			<div class="img-wrap img-wrap2">
				<div class="bg"><img src="img/p1.jpg"/></div>
				<img class="img" src="img/p2.jpg"/>
			</div>
		</div>
CSS代码如下:

.wrap{
				position: relative;
				width: 964px;
				margin: 50px auto;
				background:#333333 url(img/p1.jpg) no-repeat;
				background-size: 100% 100%;
			}
			.bg{
				position: absolute;
				width: 100%;
				height: 100%;
				top: 0px;
				left: 0px;
				right: 0px;
				-webkit-filter: blur(30px);
				filter: blur(30px);
			}
			.bg img{
				width: 100%;
				height: 100%;
				opacity: 0.6;
				filter: alpha(opacity=60);
			}
			.img-wrap{
				position: relative;
				width: 100%;
				height: 100%;
				text-align: center;
				font-size: 0px;
				background: rgba(0,0,0,0.6);
			}
			.img-wrap .img{
				position: relative;
				z-index: 3;
			}
运动效果与1相同。



猜你喜欢

转载自blog.csdn.net/Doulvme/article/details/78923797