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

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

问题描述

我最近浏览了我的CSS文件,将我所有的6位十六进制代码切换为简单的3位代码(例如,我的 #FDFEFF 缩写为 #FFF )。它呈现出与以前几乎完全相同的颜色,在我看来,部分之间的部分是相当无用的,删除它们保存了我的CSS文件中的整个300字节。

I recently went through my CSS file and switch all my 6-digit hexadecimal codes to simple 3-digit codes (for example, my #FDFEFF got shortened to #FFF). It renders pretty much the exact same color as before, 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.

您使用的是哪个版本?我很少经常使用只使用3位数代码的网站(或者我猜我从来没有经历过那些)。

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

推荐答案

3位数代码是缩写,#123 #112233 相同。在您给出的示例中,您(有效地)将 #FDFEFF 替换为 #FFFFFF

The 3-digit codes are shorthand, #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.

它不是重要哪个版本,因为这样,但3位数字的颜色代码意味着你有一点点选择在阴影。如果你觉得节省300字节是值得的,然后继续使用3位数的代码,但除非你设计的低带宽情况,这300字节不会真的保存你这么多。

It doesn't "matter" which version you use, as such, but 3-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 3-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天全站免登陆