在CSS中,HSL值可以是浮点数吗?

发布于 2024-11-02 08:51:33 字数 374 浏览 7 评论 0原文

CSS3 规范仅指定:

函数符号中 HSLA 颜色值的格式为“hsla(”,后跟色调(以百分比表示)、饱和度和亮度,以及一个 ,后跟“)”。

那么我是否可以理解这些值不会被解释为整数而是浮点数?示例:

hsla(200.2, 90.5%, 10.2%, .2)

这将极大地扩展 HSL 覆盖的较小(相对于 RGB)颜色范围。

它似乎在 Chrome 中渲染得很好,尽管我不知道他们是否只是将其解析为 INT 值或什么。

The CSS3 spec only specifies that:

The format of an HSLA color value in the functional notation is ‘hsla(’ followed by the hue in degrees, saturation and lightness as a percentage, and an , followed by ‘)’.

So am I to understand that these values would be interpreted not as integers but as floats? Example:

hsla(200.2, 90.5%, 10.2%, .2)

That would dramatically expand the otherwise small (relative to RGB) range of colors covered by HSL.

It seems to render fine in Chrome, though I don't know if they simply parse it as an INT value or what.

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

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

发布评论

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

评论(3

月寒剑心 2024-11-09 08:51:33

HSL 值在传递给系统之前会转换为十六进制 RGB 值。由设备决定将“设备色域”(可显示的颜色范围)之外的任何生成的 RGB 值修剪为可显示的值。 RGB 值以十六进制表示。这是浏览器将 HSL 值转换为 RGB 值的指定算法。标准未指定舍入行为 - 并且有多种舍入方法,因为 C 或 C++ 中似乎没有内置舍入函数。

HOW TO RETURN hsl.to.rgb(h, s, l): 
       SELECT: 
      l<=0.5: PUT l*(s+1) IN m2
      ELSE: PUT l+s-l*s IN m2
       PUT l*2-m2 IN m1
       PUT hue.to.rgb(m1, m2, h+1/3) IN r
       PUT hue.to.rgb(m1, m2, h    ) IN g
       PUT hue.to.rgb(m1, m2, h-1/3) IN b
       RETURN (r, g, b)

提议的建议

换句话说,您应该能够代表HSLA 中的颜色范围与使用 HSLA 的小数值在 RGB 中表示的颜色范围完全相同。

HSL values are converted to hexadecimal RGB values before they are handed off to the system. It's up to the device to clip any resulting RGB value that is outside the "device gamut" - the range of colors that can be displayed - to a displayable value. RGB values are denoted in Hexadecimal. This is the specified algorithm for browsers to convert HSL values to RGB values. Rounding behavior is not specified by the standard - and there are multiple ways of doing rounding since there doesn't appear to be a built-in rounding function in either C or C++.

HOW TO RETURN hsl.to.rgb(h, s, l): 
       SELECT: 
      l<=0.5: PUT l*(s+1) IN m2
      ELSE: PUT l+s-l*s IN m2
       PUT l*2-m2 IN m1
       PUT hue.to.rgb(m1, m2, h+1/3) IN r
       PUT hue.to.rgb(m1, m2, h    ) IN g
       PUT hue.to.rgb(m1, m2, h-1/3) IN b
       RETURN (r, g, b)

From the proposed recommendation

In other words, you should be able to represent the exact same range of colors in HSLA as you can represent in RGB using fractional values for HSLA.

如果没有 2024-11-09 08:51:33

AFAIK,每个浏览器都会将它们转换为 INT。或许。如果我错了,你无论如何也无法区分。如果这真的很重要,为什么不直接截取屏幕截图并在 Photoshop 中打开它们或使用屏幕色度计。这里没有人会在没有测试的情况下得到明确的答案,并且需要 2 分钟来测试......所以......

AFAIK, every browser casts them to INTs. Maybe. If I'm wrong you won't be able to tell the difference anyway. If it really matters, why not just go take screenshots an open them in photoshop or use an on-screen color meter. Nobody here is going to have a definitive answer without testing it, and it takes 2 minutes to test... so...

少女的英雄梦 2024-11-09 08:51:33

我不太清楚,但是输入一些浮点数并看看它是否有效是有意义的?尝试使用小数需要两秒钟,并且没有..

I wouldn't know exactly, but it makes sense to just put in some floating numbers and see if it works? it takes two seconds to try with a decimal, and without..

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