CSS实现背景透明,文字不透明(兼容各浏览器)

来源:互联网 发布:李银桥和权延赤 知乎 编辑:程序博客网 时间:2024/05/22 15:03

在 FF/Chrome 等较新的浏览器中可以使用css属性background-color的rgba轻松实现背景透明,而文字保持不透明。而IE6/7/8浏览器不支持rgba,只有使用IE的专属滤镜filter:Alpha来实现,但是这样写法会把文字也变为透明,因此只有在透明容器的子节点(文本节点除外)内设置position:relative才能不继承其父元素的透明滤镜,代码如下:


 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>我是标题</title> 
<style type="text/css">
.warp{ background:#eee url(back.jpg) no-repeat left top; width:440px;height:400px;    border:1px solid #ccc;}
.content { width:180px; height:260px; margin:0px auto; padding:30px 30px;background:rgba(255, 255, 255, 0.6)!important;
filter:Alpha(opacity=60); background:#fff; /* 使用IE专属滤镜实现IE背景透明*/ }
.content p{ position:relative;} /*实现IE文字不透明*/ 
</style> 
</head> 
<body> 
<div class="warp"> 
<div class="content"><p>我是文字内容</p></div> 
</div> 
</body> 
</html>

以上代码在IE6.0+/FF3.0+/Opera10+/Chrome/Safari 均测试通过

阅读全文
0 0
原创粉丝点击