<分区>
我能否将 opacity
属性仅分配给 div
的 background
属性,而不分配给其上的文本?
我试过:
background: #CCC;
opacity: 0.6;
但这不会改变不透明度。
<分区>
我能否将 opacity
属性仅分配给 div
的 background
属性,而不分配给其上的文本?
我试过:
background: #CCC;
opacity: 0.6;
但这不会改变不透明度。
最佳答案
听起来您想使用透明背景,在这种情况下您可以尝试使用 rgba()
功能:
rgba(R, G, B, A)
R (red), G (green), and B (blue) can be either
<integer>
s or<percentage>
s, where the number 255 corresponds to 100%. A (alpha) can be a<number>
between 0 and 1, or a<percentage>
, where the number 1 corresponds to 100% (full opacity).RGBa example
background: rgba(51, 170, 51, .1) /* 10% opaque green */ background: rgba(51, 170, 51, .4) /* 40% opaque green */ background: rgba(51, 170, 51, .7) /* 70% opaque green */ background: rgba(51, 170, 51, 1) /* full opaque green */
小example显示如何 rgba
可以使用。
截至 2018 年,实际上 every browser supports the rgba
syntax .
关于CSS opacity 只给背景色,不给文字吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5135019/