CSS 如何在 HTML5 元素中设置透明背景
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16992329/
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 transparent background in HTML5 element
提问by Debugger
I want to set the opacity of an element to 0. Now if i do this, all the content of the element will inherit this property. I don't want this, i just want the background to get the opacity 0 while the content (the text for example) stays visible
我想将元素的不透明度设置为 0。现在如果我这样做,元素的所有内容都将继承这个属性。我不想要这个,我只想让背景在内容(例如文本)保持可见时获得不透明度 0
Any clues ?
任何线索?
Thanks.
谢谢。
采纳答案by Debugger
After some research I found an easy answer - background-color: transparent;
经过一番研究,我找到了一个简单的答案- background-color: transparent;
回答by PerkinsB1024
Can you set the background color instead?
你可以设置背景颜色吗?
background-color: rgba(255,255,255,0.6);
回答by laconbass
The opacity property is applied across an entire object, as you can read on the specification for it.
opacity 属性应用于整个对象,您可以阅读它的规范。
The uniform opacity setting to be applied across an entire object. Any values outside the range 0.0 (fully transparent) to 1.0 (fully opaque) will be clamped to this range. If the object is a container element, then the effect is as if the contents of the container element were blended against the current background using a mask where the value of each pixel of the mask is .
要应用于整个对象的统一不透明度设置。0.0(完全透明)到 1.0(完全不透明)范围之外的任何值都将被限制在此范围内。如果对象是一个容器元素,则效果就像使用蒙版将容器元素的内容与当前背景混合,其中蒙版的每个像素的值为 。
You can consider using rgba()
colors.
您可以考虑使用rgba()
颜色。