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

查看:149
本文介绍了如何在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天全站免登陆