CSS opacity – 實現圖片半透明效果的代碼

來源:互聯網
上載者:User

前幾天一位做網頁設計的朋友問我這個問題:如何通過CSS來實現圖片半透明效果,並且在IE和Mozilla上都可以得到支援。下面將我的方法分享給大家。

為通過CSS實現的圖片透明效果

這個效果在IE和Mozilla瀏覽器上都可以工作,代碼如下

<img alt="powerbookg4.jpg" src="archives/images/powerbookg4.jpg" width="250" height="60" style="-moz-opacity:0.5; filter:alpha(opacity=50);cursor:hand;" onmouseover="this.style.MozOpacity=1;
this.filters.alpha.opacity=100" onmouseout="this.style.MozOpacity=0.5;
this.filters.alpha.opacity=50">

在IE中需要通過"filter"來定義透明度"opacity",而在Mozilla中是可以直接解析"opacity",所以如果要使得這個效果在兩種瀏覽器中都得到支援,需要把兩種設定都加進去。針對IE的設定:this.filters.alpha.opacity=50 而針對Mozilla的設定:this.style.MozOpacity=0.5. 大家可以直接用這行代碼給圖片定義,只須修改圖片地址就能實現效果。

Image with link:

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.