你应该使用rgba(0,0,0,0)或rgba(255,255,255,0)CSS的透明度吗? [英] Should you use rgba(0, 0, 0, 0) or rgba(255, 255, 255, 0) for transparency in CSS?
问题描述
应使用 rgba(0,0,0,0)
或 rgba(255,255,255,0)
推荐答案
由于最后一个参数是alpha参数,如果将其设置为0,则意味着完全透明,前三个参数(红色,绿色,蓝色)
Given that the last parameter is the "alpha" parameter, if you set it to 0 it will mean "completely transparent", and the first three parameters (red, green, blue) won't matter because you won't be able to see the color anyway.
考虑到这一点,我仍然会选择 rgba(0,0,0, 0)
,因为:
With that in mind, I would still choose rgba(0, 0, 0, 0)
because:
- 键入较少,
- 如果Alpha值更改为不受欢迎的值,您会看到一个明显的问题。
您可以完全避免使用 rgba
模型,并使用 transparent
值,根据 w3.org ,相当于透明黑色并应计算为 rgba(0,0,0,0)
。例如:
You could avoid the rgba
model altogether and use the transparent
value instead, which according to w3.org, is equivalent to "transparent black" and should compute to rgba(0, 0, 0, 0)
. For example:
h1 {
background-color: transparent;
}
这会节省你另外几个字节,而你使用透明度的意图是显而易见的以防万一不熟悉RGBA)。
This saves you yet another couple bytes while your intentions of using transparency are obvious (in case one is unfamiliar with RGBA).
这篇关于你应该使用rgba(0,0,0,0)或rgba(255,255,255,0)CSS的透明度吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!