如何在 CSS 中使用 3 位颜色代码而不是 6 位颜色代码? [英] How can I use 3-digit color codes rather than 6-digit color codes in CSS?

查看:36
本文介绍了如何在 CSS 中使用 3 位颜色代码而不是 6 位颜色代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近浏览了我的 CSS 文件并将我所有的六位数十六进制代码转换为简单的三位数代码(例如,我的 #FDFEFF 被缩短为 #FFF).

I recently went through my CSS file and switched all my six-digit hexadecimal codes to simple three-digit codes (for example, my #FDFEFF got shortened to #FFF).

它呈现的颜色与以前几乎完全相同,在我看来,中间部分相当无用,删除它们为我的 CSS 文件节省了整整 300 个字节.

It renders pretty much the exact same color as before, and it seems to me that the in-between parts are fairly useless and removing them saved me an entire 300 bytes in my CSS file.

你使用哪个版本有关系吗?我很少遇到只使用三位数代码的网站(或者我想我从来没有遇到过这样的网站).在六位数代码上使用三位数代码仍然完全有效,还是应该使用完整的六位数代码?

Does it matter which version you use? I rarely ever run across websites that use only the three-digit codes (or I guess I just never run across ones that do). Is it still perfectly valid to use three-digit codes over six-digit codes, or are we supposed to use the full six-digit codes?

推荐答案

三位数代码是简写,#123#112233 相同.在您给出的示例中,您已经(有效地)将 #FDFEFF 替换为 #FFFFFF,它接近原始颜色,但显然不准确.

The three-digit codes are a shorthand, and #123 is the same as #112233. In the example you give, you've (effectively) swapped #FDFEFF for #FFFFFF, which is close to the original colour, but obviously not exact.

这并不重要";您使用哪个版本,因此,但三位数的颜色代码意味着您在色调方面的选择要少一些.如果您觉得节省 300 字节值得,那么继续使用三位数代码,但除非您是为低带宽情况设计,否则这 300 字节不会真正为您节省那么多.

It doesn't "matter" which version you use, as such, but three-digit colour codes mean you have a little less choice in shades. If you feel that saving 300 bytes is worth that, then go ahead and use the three-digit codes, but unless you're designing for a low-bandwidth situation those 300 bytes won't really save you all that much.

这篇关于如何在 CSS 中使用 3 位颜色代码而不是 6 位颜色代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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