带 Alpha 通道的颜色的十六进制表示?

发布于 2024-08-04 11:07:16 字数 80 浏览 2 评论 0原文

关于如何以十六进制格式表示颜色(包括 Alpha 通道),是否有 W3 或任何其他值得注意的标准?

是#RGBA 还是#ARGB?

Is there a W3 or any other noteworthy standard on how to represent a color (including alpha channel) in hex format?

Is it #RGBA or #ARGB?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

杀お生予夺 2024-08-11 11:07:16

在 CSS 3 中,引用规范,“RGBA 值没有十六进制表示法”(请参阅​​ CSS 3 级规范)。相反,您可以使用带有小数或百分比的 rgba() 函数表示法,例如 rgba(255, 0, 0, 0.5) 将是 50% 透明的红色。 RGB 通道为 0-255 或 0%-100%,alpha 为 0-1。

在 CSS 颜色级别 4 中,您可以使用 8 位十六进制颜色的第 7 个和第 8 个字符或 4 位十六进制颜色的第 4 个字符指定 Alpha 通道(请参阅 CSS 颜色模块级别 4 规范*)

截至 2022 年 7 月,预计超过 95% 的用户了解 #RGBA 格式

自 2016 年 9 月发布的 Firefox 49 起就开始支持它

  • (Mozilla 错误 567283)。
  • Safari 10,2016 年 9 月发布。Chrome
  • 62,2017 年 10 月发布。对于早期版本,您可以启用实验性 Web 功能来使用此语法。请参阅 Chromium 问题 618472Webkit 错误 150853
  • Opera 52,2018 年 3 月发布(或启用实验性 Web 功能时发布 Opera 39)。
  • Edge 79,2020 年 1 月发布(基于 Chromium 的 Edge 的第一个版本)
  • Samsung Internet 8.2,2018 年 12 月发布
  • Android P(您的应用程序必须针对 Android P 或更高版本)

不支持:

  • IE
  • Original Edge(版本号高达 和包括 18)
  • Opera Mini
  • UC 浏览器

最新的浏览器支持信息可在 CanIUse.com 上获取

In CSS 3, to quote from the spec, "there is no hexadecimal notation for an RGBA value" (see CSS Level 3 spec). Instead you can the use rgba() functional notation with decimals or percentages, e.g. rgba(255, 0, 0, 0.5) would be 50% transparent red. RGB channels are 0-255 or 0%-100%, alpha is 0-1.

In CSS Color Level 4, you can specify the alpha channel using the 7th and 8th characters of an 8 digit hex colour, or 4th character of a 4 digit hex colour (see CSS Color Module Level 4 spec*)

As of July 2022, >95% of users can be expected to understand the #RGBA format

It has been supported since:

  • Firefox 49, released Sept 2016 (Mozilla bug 567283).
  • Safari 10, released Sept 2016.
  • Chrome 62, released Oct 2017. For earlier versions you could enable experimental web features to use this syntax. See Chromium Issue 618472 and Webkit bug 150853.
  • Opera 52, released March 2018 (or Opera 39 when experimental web features are enabled).
  • Edge 79, released Jan 2020 (the first version of Edge based on Chromium)
  • Samsung Internet 8.2, released Dec 2018
  • Android P (your app must target Android P or newer)

It is not supported in:

  • IE
  • Original Edge (version numbers up to and including 18)
  • Opera Mini
  • UC Browser

Up to date browser support information is available on CanIUse.com

温柔少女心 2024-08-11 11:07:16

看起来没有十六进制 alpha 格式: http://www.w3.org/TR/css3-color/< /a>

无论如何,如果您使用像 SASS 这样的 CSS 预处理器,那么您可以将十六进制传递给 rgba
背景:

rgba(#000, 0.5);

预处理器只是自动将十六进制代码转换为RGB。

It looks like there is no hex alpha format: http://www.w3.org/TR/css3-color/

Anyway, if you use a CSS preprocessor like SASS then you can pass an hex to rgba:
background:

rgba(#000, 0.5);

And the preprocessor just converts the hex code to rgb automatically.

倾城月光淡如水﹏ 2024-08-11 11:07:16

我不确定是否有官方标准 -

RGBA 是我见过的 Web 表示形式
Macromedia 和其他人使用 ARGB

我相信 RGBA 是更常见的表示形式。

如果有帮助的话,这是来自 W3 for CSS3
http://www.w3.org/TR/css3-color/#rgba -color

编辑 (Patrick):引用上述 W3 链接

与 RGB 值不同,RGBA 值没有十六进制表示法

I'm not sure if there is an official standard-

RGBA is the representation I've seen for Web
Macromedia and others use ARGB

I believe that RGBA is the more common representation.

If it helps this is from W3 for CSS3
http://www.w3.org/TR/css3-color/#rgba-color

EDIT (Patrick): quote from the above W3 link

Unlike RGB values, there is no hexadecimal notation for an RGBA value

梨涡 2024-08-11 11:07:16

Chrome 52+ 支持 alpha 十六进制:

background: #56ff0077;

对于较旧的浏览器,您必须使用:

background-color: rgba(255, 220, 0, 0.3);

Chrome 52+ supports alpha hex:

background: #56ff0077;

For older browsers, you'll have to use:

background-color: rgba(255, 220, 0, 0.3);
烦人精 2024-08-11 11:07:16

您可以尝试将十六进制颜色放入 GIMP 或 photoshop 的颜色选择器中以获取 RGB 值,然后使用 alpha 值。例如。红色是 #FF0000rgb(255,0,0) 如果您想要 alpha 值为 0.5 的红色,则 rgba(255,0,0, .5)

也许不完全是你想要的,但希望有帮助。

You could try putting the hex color into the color picker of GIMP or photo shop to get the RGB value and then using the alpha value. eg. red is #FF0000 or rgb(255,0,0) if you want red with an alpha value of .5 then rgba(255,0,0,.5).

Maybe not exactly what you wanted but hopefully helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文