半透明div并且在IE火狐下兼容

本文介绍了如何使用CSS实现网页背景透明、文字不透明的效果,并详细解释了不同浏览器(如IE和Firefox)之间的兼容性问题及解决方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


<!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">

*{margin:0 auto;}
body{ background:url(sl.jpg) no-repeat; }
.div{background:rgba(0, 0, 0, 0.4) none repeat scroll 0 0 !important;/*实现FF背景透明,文字不透明*/filter:Alpha(opacity=40); background:#000000;/*实现IE背景透明*/color:#FFF;width:500px;height:470px;border:1px solid #FF0;font-size:18px;text-align:center;font-weight:bold;margin:30px;}
.div p{position:relative;}

</style>


</head>
<body>
<div class="div"><p >我是文字</p></div>
</body>
</html>

IE:外层filter,内层position:relative或absolute。
FF:外层不使用opacity,而用background:rgba()。
<!--
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
    <style>
        #wrapper
        {
            background: #369;
            width:300px;
            height:150px;
        }
        #div1
        {
            -moz-opacity: 0.3; /* FF 3.5以下 */
            opacity: 0.3; /* FF 3.5及以上 */
            filter: alpha(opacity=30); /* IE6及以上 */
            background: #fff;
            width: 200px;
            height: 50px;
        }
        #div2
        {
            background: rgba(255, 255, 255, 0.3) !important; /* IE无效,FF有效 */
            background: #fff;
            filter: alpha(opacity=30);
            width: 200px;
            height: 50px;
        }
        #div2 span
        {
            position: relative;
        }
    </style>
</head>
<body>
    <div id="wrapper">
        <div id="div1">
            <span>图层背景半透明,字体颜色也半透明</span>
        </div>
        <br />
        <div id="div2">
            <span>图层背景半透明,字体颜色不半透明</span>
        </div>
    </div>
</body>
</html>

-->





.con{
background:rgba(255, 255, 255, 0.8) none repeat scroll 0 0 !important;/*实现FF背景透明,文字不透明*/
filter:Alpha(opacity=80); background:#fff;/*实现IE背景透明*/
}
.con p{ position:relative;}/*实现IE文字不透明*/

<div class="con">
<p>文字</p>
</div>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值