CSS 图像透明度opacity兼容性介绍

以前的兼容

复制代码代码如下:
<span class="class">.transparent_class</span> <span class="rules">{
<span class="rule"><span class="attribute">-ms-filter</span>:<span class="value"><span class="string">"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"</span>;</span></span> <span class="comment">/* ie8 */</span>
<span class="rule"><span class="attribute">filter</span>:<span class="value"><span class="function">alpha(opacity=<span class="number">50</span>)</span>;</span></span> <span class="comment">/* ie5-7 */</span>
<span class="rule"><span class="attribute">-moz-opacity</span>:<span class="value"><span class="number">0.5</span>;</span></span> <span class="comment">/* old mozilla browser like netscape */</span>
<span class="rule"><span class="attribute">-khtml-opacity</span>:<span class="value"> <span class="number">0.5</span>;</span></span> <span class="comment">/* for really really old safari */</span>
<span class="rule"><span class="attribute">opacity</span>:<span class="value"> <span class="number">0.5</span>;</span></span> <span class="comment">/* css standard, currently it works in most modern browsers like firefox, */</span>
<span class="rule">}</span></span>

现在的兼容

复制代码代码如下:
<span class="class">.transparent_class</span> <span class="rules">{
<span class="rule"><span class="attribute">-ms-filter</span>:<span class="value"><span class="string">"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"</span>;</span></span> <span class="comment">/* ie8 */</span>
<span class="rule"><span class="attribute">filter</span>:<span class="value"><span class="function">alpha(opacity=<span class="number">50</span>)</span>;</span></span> <span class="comment">/* ie5-7 */</span>
<span class="rule"><span class="attribute">opacity</span>:<span class="value"> <span class="number">0.5</span>;</span></span> <span class="comment">/* css standard, currently it works in most modern browsers */</span>
<span class="rule">}</span></span>


复制代码代码如下:
<!DOCTYPE html>
<html>
<head>
<style>
img
{
opacity:0.4;
filter:alpha(opacity=40); /* For IE8 and earlier */
}
img:hover
{
opacity:1.0;
filter:alpha(opacity=100); /* For IE8 and earlier */
}
</style>
</head>
<body>
<h1>图像透明度</h1>
<img src="/i/tulip_peach_blossom_w_s.jpg" alt="Peach Blossom" />
<p><b>注释:</b>在 IE 中,必须添加 <!DOCTYPE>,这样才能将 :hover 选择器用于除了 <a> 之外的其它元素。</p>
</body>
</html>

CSS 图像透明度opacity兼容性介绍