问题描述
在寻找大量主题的教程时,我经常看到RGB&在HTML/CSS中,使用RGBA代替十六进制代码表示颜色.
While looking at tutorials for a multitude of topics, I've often seen RGB & RGBA be used instead of hex codes for colours in HTML/CSS.
有人可以确切地向我解释RGB,RGBA,十六进制之间的区别是什么,什么时候应该使用它们/使用一个相对于另一个的好处?
Can someone explain to me exactly what is the difference between RGB, RGBA, hex, and when should each be used/the benefit of using one over the other?
推荐答案
RGB和十六进制颜色之间没有区别.
There's no differences between a RGB and hex color.
FF = 255
=> #FFFFFF = rgb(255,255,255)
=> #FFFFFF = rgb(255,255,255)
分解六种颜色时:
#FF FF FF
red green blue
但是使用rgb a (alpha),您可以添加alpha变量,从而为您的颜色添加不透明度.
But with rgba (alpha) you can add a alpha variable it add an opacity to your color.
您可以使用RGB和十六进制,具体取决于您的喜好
You can use RGB and HEX it depends of your preferences
示例:
div {
width:100px;
height:100px;
border:solid 1px black;
display:inline-block;
}
.rgb{
background-color:rgb(124,220,50); /* to hexa = 7C, DC, 32 */
}
.hexa{
background-color:#7CDC32;
}
.rgba{
background-color:rgba(124,220,50,0.2); /* opacity = 20% */
}
<div class="rgb">rgb</div>
<div class="hexa">hexa</div>
<div class="rgba">rgba</div>
这篇关于十六进制颜色,RGB和& RGBA,何时应使用它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!