CSS中轻松实现Firefox与IE透明度

你对CSS中实现Firefox与IE透明度的概念是否了解,这里和大家分享几种实现Firefox与IE透明度的方法,希望对你的学习有所帮助。

CSS中实现Firefox与IE透明度(opacity)的不同方法

Dreamweaver提供的透明度样式只能支持IE,想要在Firefox下实现,需要自己手写。如下:

1.IE6设置透明度

CSS设置

filter:alpha(opacity=50);

javascript设置

IESpanJs.style.filter=“alpha(opacity=50)”;

2.Firefox3.5设置透明度

Firefox3.5支持CSS3,已经不对原来的透明度样式(-moz-opacity)提供支持(网上查的),在本人的Firefox3.5.5上测试后,发现确实如此,现在的透明度设置为:

CSS设置

opacity:0.5;

javascript设置

FirefoxSpanJs.style.mozOpacity=“0.5″;

3.Firefox3.5以前版本设置透明度

CSS设置

-moz-opacity:0.5;

javascript设置

FirefoxSpanJs.style.mozOpacity=“0.5″;

4.demo代码

 
 
  1. <HTML>   
  2. <HEAD>   
  3. <style type=“text/CSS”>   
  4. .IECSS {   
  5. display:-moz-inline-box;   
  6. display:inline-block;   
  7. width:100;   
  8. height:100;   
  9. background-color:red;   
  10. filter:alpha(opacity=50);   
  11. }   
  12. .Firefox35CSS {   
  13. display:-moz-inline-box;   
  14. display:inline-block;   
  15. width:100;   
  16. height:100;   
  17. background-color:blue;   
  18. opacity:0.5;   
  19. }   
  20. .FirefoxCSS {   
  21. display:-moz-inline-box;   
  22. display:inline-block;   
  23. width:100;   
  24. height:100;   
  25. background-color:yellow;   
  26. -moz-opacity:0.5;   
  27. }   
  28. </style>   
  29.     
  30. <script>   
  31. window.onload = function() {   
  32. //设置IE   
  33. var IESpanJs = document.getElementById(“IESpanJs”);   
  34. IESpanJs.style.display = “inline-block”;  //IE支持   
  35. IESpanJs.style.width = 100;   
  36. IESpanJs.style.height = 100;   
  37. IESpanJs.style.backgroundColor = “red”;   
  38. IESpanJs.style.filter=“alpha(opacity=50)”;   
  39.     
  40. //设置Firefox3.5.*   
  41. var Firefox35SpanJs = document.getElementById(“Firefox35SpanJs”);   
  42. try   
  43. {   
  44. Firefox35SpanJs.style.display = “-moz-inline-box”; //Firefox支持   
  45. }   
  46. catch (e)   
  47. {   
  48. Firefox35SpanJs.style.display = “inline-block”; //支持IE   
  49. }   
  50.     
  51. Firefox35SpanJs.style.width = 100;   
  52. Firefox35SpanJs.style.height = 100;   
  53. Firefox35SpanJs.style.backgroundColor = “blue”;   
  54. Firefox35SpanJs.style.opacity=“0.5″;   
  55.     
  56. //设置Firefox   
  57. var FirefoxSpanJs = document.getElementById(“FirefoxSpanJs”);   
  58. try   
  59. {   
  60. FirefoxSpanJs.style.display = “-moz-inline-box”; //Firefox支持   
  61. }   
  62. catch (e)   
  63. {   
  64. FirefoxSpanJs.style.display = “inline-block”; //支持IE   
  65. }   
  66.     
  67. FirefoxSpanJs.style.width = 100;   
  68. FirefoxSpanJs.style.height = 100;   
  69. FirefoxSpanJs.style.backgroundColor = “yellow”;   
  70. FirefoxSpanJs.style.mozOpacity=“0.5″;   
  71.     
  72. }   
  73. </script>   
  74.     
  75. </HEAD>   
  76.     
  77. <BODY>   
  78. <span id=“IESpanCSS” class=“IECSS”>IE_CSS</span>   
  79. <span id=“Firefox35SpanCSS” class=“Firefox35CSS”>Firefox3.5_CSS</span>   
  80. <span id=“FirefoxSpanCSS” class=“FirefoxCSS”>Firefox_CSS</span>   
  81. <br>   
  82. <br>   
  83. <span id=“IESpanJs”>IE_Js</span>   
  84. <span id=“Firefox35SpanJs”>Firefox3.5_Js</span>   
  85. <span id=“FirefoxSpanJs”>Firefox_Js</span>   
  86. </BODY>   
  87. </HTML> 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值