HTML设置页面透明度<转载>

W3C标准属性是opacity,现代浏览器都支持,但IE6/7/8却不支持该属性。

在Firefox,Safari,Opera,Chrome中测试都支持opacity。如设置div的透明度为40%。

<!DOCTYPE HTML>
<html>
  <head>
    <title>set div opacity</title>
    <style>
        .wrapper {
            border:solid 1px gray;
            opacity:0.4;
        }
    </style>
  </head>
  <body>
    <div class="wrapper">
        set div opacity
    </div>               
  </body>
</html>

注意:firefox3.5以下版本使用-moz-opacity属性。

IE6/7/8中复杂些

1、IE4-IE7使用filter: alpha(opacity=xx),但要同时使该元素拥有hasLayout

<!DOCTYPE HTML">
<html>
  <head>
    <title>set div opacity</title>
    <style>
        .wrapper {
            border:solid 1px gray;
            background-color:green;
            filter: alpha(opacity=40);
            zoom:1;
        }
    </style>
  </head>

  <body>
    <div class="wrapper">
        set div opacity
    </div>               
  </body>
</html>

2、IE8下也可以用上面的filter: alpha(opacity=10),且不用设置zoom使元素拥有layout。同时IE8可以使用-ms-filter属性。如
-ms-filter: “alpha(opacity=10)”; /* IE 8 */

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值