gpt4 book ai didi

html - 样式 ="color: #FFF;"呈现为#F0F0F0 还是#FFFFFF?

转载 作者:技术小花猫 更新时间:2023-10-29 11:32:50 25 4
gpt4 key购买 nike

当使用“shorthand hexidecimal”(style="color: #FFF;")定义颜色时,是否有定义的方法来扩展shorthand? (style="color: #F0F0F0;"style="color: #FFFFFF;")

所有浏览器都使用相同的扩展方法吗?这种行为是否符合规范(如果是,它是在哪里定义的)?扩展方法在 CSS 1/2/3 之间可能会有所不同吗?

我观察到“大多数浏览器”扩展为 #FFFFFF

是否有其他地方(HTML/CSS 之外)允许使用这种简写形式,但展开方式不同?

我一直避免使用速记十六进制,因为我从来不知道这些问题的答案......

最佳答案

CSS 2.1(http://www.w3.org/TR/CSS2/syndata.html#value-def-color):

The three-digit RGB notation (#rgb) is converted into six-digit form (#rrggbb) by replicating digits, not by adding zeros. For example, #fb0 expands to #ffbb00. This ensures that white (#ffffff) can be specified with the short notation (#fff) and removes any dependencies on the color depth of the display.

CSS 1的措辞, CSS 3是相同的。 CSS 4 draft说类似的话。

Internet ExplorerFirefox文档说明了相同的方法。

作为实际示例,请查看此代码段,其中包含 3 <div> s 风格

div { width: 100px; height: 100px;  }
<div style="background-color:#f0f0f0;">#f0f0f0</div>
<div style="background-color:#fff;">#fff</div>
<div style="background-color:#ffffff;">#ffffff</div>

在 Mac OS X 10.6 上,所有 Firefox 3.6、Opera 10.10、Safari 4 呈现 #fff作为#ffffff .

Behavior in different browsers

我看不出浏览器或标准将来想要偏离这种扩展的原因,因为颜色 #ffffff远比 #f0f0f0 常见.

关于html - 样式 ="color: #FFF;"呈现为#F0F0F0 还是#FFFFFF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2899197/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com