---
title: "透明度的兼容写法总结"
author: "dreaming."
date: "2014-05-23T17:46:20Z"
tags: []
categories: ["Web前端"]
slug: "untitled"
draft: false
lastmod: "2014-05-23T17:46:20Z"
id: 2070507
url: "https://linuxzhixin.iteye.com/blog/2070507"
---

&lt;style type="text/css"&gt;

 

.tou{width:100px; height:100px;background-color:#999; filter:alpha(opacity=20);opacity:0.2;}

&lt;/style&gt;

 

&lt;div class="tou"&gt;透明层&lt;/div&gt;

 

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**

解释：filter:alpha(opacity=20) 是针对IE的，不写， IE9中可以，但在 IE9 以下（IE8,IE7,IE6）的浏览器都不行。

opacity:0.2 是针对火狐，谷歌的。

我一直以为 filter:alpha(opacity=20)这种写法不兼容IE6，因为我在IETest上测试不可以。后来在xp系统IE6上测试，却可以。说明IETest的IE6有Bug。

 

使用时这两种一定要全部写，才兼容各种浏览器。