Author 王平安
E-mail pingan8787@qq.com
博 客 www.pingan8787.com
微 信 pingan8787
每日文章 https://0x9.me/KMrv3

demo1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>背景透明,文字不透明</title>
<style>
*{
padding: 0;
margin: 0;
}

body{
padding: 50px;
background: url(img/bg.png) 0 0 repeat;
}

.demo{
padding: 25px;
background-color: rgba(0,0,0,0.5);/* IE9、标准浏览器、IE6和部分IE7内核的浏览器(如QQ浏览器)会读懂 */
}
.demo p{
color: #FFFFFF;
}
@media \0screen\,screen\9 {/* 只支持IE6、7、8 */
.demo{
background-color:#000000;
filter:Alpha(opacity=50);
position:static; /* IE6、7、8只能设置position:static(默认属性) ,否则会导致子元素继承Alpha值 */
*zoom:1; /* 激活IE6、7的haslayout属性,让它读懂Alpha */
}
.demo p{
position: relative;/* 设置子元素为相对定位,可让子元素不继承Alpha值 */
}
}

</style>
</head>
<body>

<div class="demo">
<p>背景透明,文字不透明</p>
</div>

</html>

demo2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>opacity</title>
<style>
*{
padding: 0;
margin: 0;
}
body{
padding: 50px;
background: url(http://static.cnblogs.com/images/logo_small.gif) 0 0 repeat;
}

.demo{
width: 200px;
height: 200px;
position: relative;
}
.demo-bg{
position: absolute;
left: 0;
top: 0;
z-index: 0;
width: 200px;
height: 200px;
background-color:#000000;
filter:Alpha(opacity=50);
background-color: rgba(0,0,0,0.5);
}
.demo-txt{
position: relative;
z-index: 1;
color: #FFFFFF;
}
</style>
</head>
<body>

<div class="demo">
<div class="demo-bg"></div><!-- 透明背景 -->
<div class="demo-txt">测测</div><!-- 不透明文字 -->
</div>

</html>