2014-05-24 37 views
1

我想使灰色bgcolor具有透明度。而是其内容变得透明而不是bgcolor。CSS使背景颜色透明

body { 
    background-color: gray; 
    /* IE 8 */ 
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; 

    /* IE 5-7 */ 
    filter: alpha(opacity=50); 

    /* Netscape */ 
    -moz-opacity: 0.5; 

    /* Safari 1.x */ 
    -khtml-opacity: 0.5; 

    /* Good browsers */ 
    opacity: 0.5; 
} 
+0

http://stackoverflow.com/questions/806000/transparent-background-but-not-the-content-text-images-inside-it-in-css-on – Banana

回答

2

background-colorrgba(red, green, blue, alpha)其中red,​​blue和是0255alpha之间是01之间,0是完全透明的,并1完全不透明。

也请看看:How do I give text or an image a transparent background using CSS?

+0

这将工作,虽然在旧的浏览器? – CudoX

+0

制作了一个快速网站,我们将看到:browsershots.org/http://testnaman.neocities.org/quicktest.html。编辑:似乎工作得很好。 (上述链接仅适用于美国东部时间2014年5月24日晚11点10分左右) – Winestone

0

如果你不关心巨大的与旧的浏览器的兼容性,那么你可以使用新的CSS3 RGBA颜色定义:

background-color: rgba(0, 0, 0, 0.5);

这将设置你的元素透明背景颜色。