背景半透明文字不透明效果。(兼容IE,FF)

IE:外层filter,内层position:relative或absolute。
FF:外层不使用opacity,而用background:rgba()。

 

<html>
<head>
    
<style>
        #wrapper
        
{
            background
: #369;
            width
:300px;
            height
:150px;
        
}
        #div1
        
{
            -moz-opacity
: 0.3; /* FF 3.5以下 */
            opacity
: 0.3; /* FF 3.5及以上 */
            filter
: alpha(opacity=30); /* IE6及以上 */
            background
: #fff;
            width
: 200px;
            height
: 50px;
        
}
        #div2
        
{
            background
: rgba(255, 255, 255, 0.3) !important; /* IE无效,FF有效 */
            background
: #fff;
            filter
: alpha(opacity=30);
            width
: 200px;
            height
: 50px;
        
}
        #div2 span
        
{
            position
: relative;
        
}
    
</style>
</head>
<body>
    
<div id="wrapper">
        
<div id="div1">
            
<span>图层背景半透明,字体颜色也半透明</span>
        
</div>
        
<br />
        
<div id="div2">
            
<span>图层背景半透明,字体颜色不半透明</span>
        
</div>
    
</div>
</body>
</html>

 

以下是rgba属性的浏览器支持情况,来源:http://css-tricks.com/rgba-browser-support/

 

posted @ 2011-03-08 15:34  martian  阅读(1905)  评论(1)    收藏  举报