简体   繁体   English

HTML RGBA颜色不透明度?

[英]Html rgba color opacity?

When we use RGBA in Html we use sth like this. 当我们在HTML中使用RGBA时,我们将使用sth这样。

<div style="Background: rgba (x, x, x, 0.dd)">Some Content</div>

How many decimals can you go in the dd (opacity) . 您可以在dd (不透明度)中输入多少个小数。 Is it browser dependent? 是否依赖浏览器? Or are its limits specified in HTML standards? 还是在HTML标准中指定了其限制?

The specification says it is a <number> which is defined as : 规范说这是一个<number> ,它定义为

zero or more digits followed by a dot (.) followed by one or more digits 零个或多个数字,后跟一个点(。),然后一个或多个数字

So there is no limit specified in the CSS spec. 因此,CSS规范中没有指定限制。

I'd be surprised if any human eye could distinguish beyond two decimal places though. 如果有人的眼睛能分辨出小数点后两位,我会感到惊讶。

The value can be any number between 0.0 and 1.0. 该值可以是0.0到1.0之间的任何数字。

The resolution depends on the color space resolution which typically is 8-bit (future may offer higher resolutions such as 10- and 12-bit, although I doubt that will happen anytime soon, but that is why a fraction is used instead of a byte value). 分辨率取决于通常为8位的色彩空间分辨率(未来可能会提供更高的分辨率,例如10位和12位,尽管我怀疑不久后会发生这种情况,但这就是为什么使用小数而不是字节的原因值)。

The value is multiplied with the byte value so it is limited what numbers you want to use and the final value is rounded to closest integer value: 该值与字节值相乘,因此限制了您要使用的数字,并且最终值四舍五入为最接近的整数值:

Internal byte value = round(alpha * 255);

(or an increment of 1 / 256 = 0.00390625 ) (或1 / 256 = 0.00390625的增量1 / 256 = 0.00390625

to give you actual change of the final byte value and the visual appearance (assuming solid background). 给您最终字节值和视觉外观的实际变化(假设纯色背景)。

I made a small script here which gives you the result from using various numbers of decimals in the fraction value - as you can see when you are at 3 decimals the values start to be similar and therefor not so useful. 我在这里做了一个小脚本,它为您提供了分数值中使用各种小数位数的结果-正如您所看到的,当您使用3个小数时,数值开始相似,因此没有太大用处。

ONLINE GENERATED TABLES HERE 此处生成在线表格

桌子

The loop to generate the table looks like this in general: 生成表的循环通常如下所示:

for (; i < 1; i += 0.1) {
    num = Math.round(i * 255, 10);
    ...
}

The opacity property has a value set to two decimals. opacity属性的值设置为两位小数。

All current browsers recognize this, the context is a little different for IE8 and below. 当前所有的浏览器都意识到这一点,对于IE8及以下版本,上下文有所不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM