在CSS中,HSL值可以是浮点数吗? [英] In CSS, can HSL values be floats?

查看:62
本文介绍了在CSS中,HSL值可以是浮点数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CSS3规范仅指定:

功能标记中的HSLA颜色值的格式为"hsla(",其后为以度,饱和度和明度为百分比的色相,以及,其后为)".

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)

这将大大扩展HSL覆盖的其他较小的颜色范围(相对于RGB).

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

尽管我不知道他们只是将其解析为INT值还是什么,但它似乎在Chrome中可以正常显示.

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

推荐答案

HSL值在移交给系统之前已转换为十六进制RGB值.由设备决定将任何超出设备色域"(可以显示的颜色范围)的结果RGB值裁剪为可显示的值.RGB值以十六进制表示.这是浏览器将HSL值转换为RGB值的指定算法.舍入行为不是标准规定的-由于在C或C ++中似乎都没有内置的舍入函数,因此有多种进行舍入的方法.

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)

来自建议的建议

换句话说,您应该能够使用HSLA的分数值来表示与HSLA中的颜色完全相同的颜色范围.

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.

这篇关于在CSS中,HSL值可以是浮点数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆