2014-05-24 265 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);

這將設置你的元素透明背景顏色。