首页 > 编程知识 正文

css rgb颜色代码,颜色格式RGB

时间:2023-05-03 13:00:13 阅读:260733 作者:4416

css颜色用rgb

While longer-winded than hexadecimal, the RGB method for color in CSS is easier to manipulate directly via JavaScript; RGB is also the method that JavaScript uses to report the color of elements, regardless of how they may have originally been set in CSS, making RGB particularly useful to understand.

尽管比十六进制更长,但用于CSS中颜色的RGB方法更容易直接通过JavaScript进行操作; RGB也是JavaScript用来报告元素颜色的方法,而不管它们最初是如何在CSS中设置的,这使得RGB特别易于理解。

RGB stands for “red, green. blue”. Like hexadecimal, RGB color is an additive system. Values of 0 for each component will produce a black color, while maximum values for each component will produce white. Modifying the values for each component will change the color; while easier to read than hexadecimal, RGB is not as instinctive as a system like HSL.

RGB代表“红色,绿色”。 蓝色”。 像十六进制一样,RGB颜色是加法系统。 每个组件的值为0将产生黑色,而每个组件的最大值将产生白色。 修改每个组件的值将改变颜色; 尽管比十六进制更易于阅读,但是RGB不像HSL这样的系统具有本能。

rgb values can be specified as values between 0 and 255:

可以将rgb值指定为0到255之间的值:

h3 { color: rgb(100, 18, 255);}

Or as percentages:

或百分比:

h3 { background: rgb(50%, 6%, 100%);} 10位彩色 (10-bit color)

It should be noted that both RGB and HSL can be defined using floating-point values:

应当注意,可以使用浮点值来定义RGB和HSL:

#genera { background-color: rgb(0.1%, 12.5%, 22%);}

This provides a far greater gamut (or range) of color values: thousands of levels of each component, for a billion possible color combinations.

这提供了更大的色域(或范围)颜色值:每种成分数千个级别,可用于十亿种可能的颜色组合。

Unfortunately, the vast majority of screens don’t yet display this breadth of color, and most browsers will currently round floating-point color values to the nearest whole number.

不幸的是,绝大多数屏幕还没有显示这种宽度的颜色,并且大多数浏览器当前会将浮点颜色值四舍五入到最接近的整数。

未来的选择 (Future Alternatives)

Future versions of the RGB CSS color specification will allow for space-separated values, rather than comma-separated:

RGB CSS颜色规范的未来版本将允许使用空格分隔的值,而不是逗号分隔的值:

h1 { color: rgb(60 30 200);}

If it is defined in the color, the alpha component is separated with a slash:

如果用颜色定义,则用斜杠分隔alpha分量 :

h1 { color: rgb(60 30 200 / 0.3);}

These syntaxes aren’t yet supported in any browser, so there’s little point in using them currently, but you should be aware that they are coming.

这些语法尚未在任何浏览器中支持,因此当前使用它们没有什么意义,但是您应该意识到它们即将到来。

RGB的用途 (Uses of RGB)

rgba is particularly useful for shadows and (to a lesser extent) gradients; in JavaScript, it is especially powerful for determining aspects of elements like contrast and luminosity. Otherwise, I generally prefer to use HSL, which I’ll look at next.

rgba对于阴影和(在较小程度上)渐变特别有用; 在JavaScript中,它对于确定元素的各个方面(例如对比度和亮度 )特别强大。 否则,我通常更喜欢使用HSL,我将在下面进行介绍。

翻译自: https://thenewcode.com/1115/Using-RGB-Color-in-CSS

css颜色用rgb

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。