Html 如何将不透明度设置为 div 的背景颜色?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6624457/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set opacity to the background color of a div?
提问by EnexoOnoma
I have this class
我有这堂课
.box { background-color:#fff; border:3px solid #eee; }
My question is how can I set an opacity to the white background only so that it will kinda mix with my background?
我的问题是如何只为白色背景设置不透明度,以便它与我的背景混合?
Thank you.
谢谢你。
采纳答案by Quentin
CSS 3 introduces rgba colour, and you can combine it with graphics for a backwards compatiblesolution.
CSS 3 引入了rgba color,您可以将其与图形结合起来以实现向后兼容的解决方案。
回答by Kevin Brown
回答by Phil
I think this covers just about all of the browsers. I have used it successfully in the past.
我认为这几乎涵盖了所有浏览器。我过去曾成功地使用过它。
#div {
filter: alpha(opacity=50); /* internet explorer */
-khtml-opacity: 0.5; /* khtml, old safari */
-moz-opacity: 0.5; /* mozilla, netscape */
opacity: 0.5; /* fx, safari, opera */
}
回答by Umair Hamid
You can use CSS3 RGBA in this way:
您可以通过以下方式使用 CSS3 RGBA:
rgba(255, 0, 0, 0.7);
0.7
means 70% opacity.
0.7
表示 70% 的不透明度。
回答by Joonas
I would say that the easiest way is to use transparent background image.
我会说最简单的方法是使用透明背景图像。
background: url("http://musescore.org/sites/musescore.org/files/blue-translucent.png") repeat top left;