DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> CSS入門知識 >> CSS詳解 >> CSS中輕松實現Firefox與IE透明度
CSS中輕松實現Firefox與IE透明度
編輯:CSS詳解     

你對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. <script>
  30. window.onload = function() {
  31. //設置IE
  32. var IESpanJS = document.getElementById(“IESpanJS”);
  33. IESpanJS.style.display = “inline-block”; //IE支持
  34. IESpanJS.style.width = 100;
  35. IESpanJS.style.height = 100;
  36. IESpanJS.style.backgroundColor = “red”;
  37. IESpanJS.style.filter=“alpha(opacity=50)”;
  38. //設置Firefox3.5.*
  39. var Firefox35SpanJS = document.getElementById(“Firefox35SpanJS”);
  40. try
  41. {
  42. Firefox35SpanJS.style.display = “-moz-inline-box”; //Firefox支持
  43. }
  44. catch (e)
  45. {
  46. Firefox35SpanJS.style.display = “inline-block”; //支持IE
  47. }
  48. Firefox35SpanJS.style.width = 100;
  49. Firefox35SpanJS.style.height = 100;
  50. Firefox35SpanJS.style.backgroundColor = “blue”;
  51. Firefox35SpanJS.style.opacity=“0.5″;
  52. //設置Firefox
  53. var FirefoxSpanJS = document.getElementById(“FirefoxSpanJS”);
  54. try
  55. {
  56. FirefoxSpanJS.style.display = “-moz-inline-box”; //Firefox支持
  57. }
  58. catch (e)
  59. {
  60. FirefoxSpanJS.style.display = “inline-block”; //支持IE
  61. }
  62. FirefoxSpanJS.style.width = 100;
  63. FirefoxSpanJS.style.height = 100;
  64. FirefoxSpanJS.style.backgroundColor = “yellow”;
  65. FirefoxSpanJS.style.mozOpacity=“0.5″;
  66. }
  67. </script>
  68. </HEAD>
  69. <BODY>
  70. <span id=“IESpanCSS” class=“IECSS”>IE_CSS</span>
  71. <span id=“Firefox35SpanCSS” class=“Firefox35CSS”>Firefox3.5_CSS</span>
  72. <span id=“FirefoxSpanCSS” class=“FirefoxCSS”>Firefox_CSS</span>
  73. <br>
  74. <br>
  75. <span id=“IESpanJS”>IE_JS</span>
  76. <span id=“Firefox35SpanJS”>Firefox3.5_JS</span>
  77. <span id=“FirefoxSpanJS”>Firefox_JS</span>
  78. </BODY>
  79. </Html>

文章來源: Div-CSS.net設計網 參考:http://www.div-CSS.Net/div_CSS/topic/index.ASP?id=10037

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved