CSS不透明度只有背景颜色不是文本吗?

参见英文答案 > <a href="/questions/8

background: #CCC;
opacity: 0.6;

/how-do-i-give-text-or-an-image-a-transparent-background-using-css” dir=”ltr”>How do I give text or an image a transparent background using CSS?                                    24个答案                            我可以分配不透明度属性到div的背景属性,而不是它的文本?

我试过了:

background: #CCC;
opacity: 0.6;

但这不会改变不透明度。

最佳答案
听起来你想使用透明的背景,在这种情况下你可以尝试使用rgba()功能:

rgba()

Colors can be defined in the Red-green-blue-alpha model (RGBa) using the rgba() functional notation. RGBa extends the RGB color model to include the alpha channel, allowing specification of the opacity of a color.
a means opacity: 0=transparent; 1=opaque;

06000

样品用量:

#div {
    background: rgb(54, 25, 25); /* Fall-back for browsers that don't
                                    support rgba */
    background: rgba(54, 25, 25, .5);
}

Demo

检查http://caniuse.com/#search=rgba以查看浏览器的支持

转载注明原文:CSS不透明度只有背景颜色不是文本吗? - 代码日志