如何将整个 css 文件的所有颜色代码 #XXYYZZ 转换为较短的 3 字符版本 #XYZ?

发布于 2024-08-19 08:21:52 字数 54 浏览 16 评论 0原文

如何将整个 css 文件的所有颜色代码 #XXYYZZ 转换为较短的 3 字符版本 #XYZ?

How to convert all color code #XXYYZZ to shorter 3 character version #XYZ of whole css file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

枫林﹌晚霞¤ 2024-08-26 08:21:52

您可以转换为较短的 3 字符版本,仅用以下方式表示的颜色:#RRGGBB,其中第一个和第二个字符相同,第三个和第四个字符相同,第五个和第六个字符相同。

因此:#CC00DD 可以缩短为 #C0D,而 #CC01DD 则不能。

缩短 CSS 文件中所有可能颜色的快速方法是使用支持正则表达式的编辑器(例如 Linux 上的 kwrite 或 kate)打开文件,并替换(忽略大小写)以下正则表达式:

#([ 0-9A-F])\1([0-9A-F])\2([0-9A-F])\3

替换文本:

#\1\2\3 与凯特一起测试

否则,如果您只需要压缩颜色,则可以使用此工具代码,您可以取消选中除“尽可能压缩颜色代码”之外的所有选项。

You can convert to the shorter 3-character version only colors expressed this way: #RRGGBB where the first and the second characters are the same, the third and fourth characters are the same and the fifth and sixth characters are the same.

So: #CC00DD can be shortened to #C0D while #CC01DD cannot.

A quick way to shorten all the possible colors in a CSS file is to open the file with an editor supporting regular expressions (for example kwrite or kate on linux) and replace (ignoring case) the following regular expression:

#([0-9A-F])\1([0-9A-F])\2([0-9A-F])\3

with this substitution text:

#\1\2\3

Tested with kate.

Otherwise you can use this tool where, if you only need to compress color codes, you can uncheck all the options except the "Compress color codes where possible".

花落人断肠 2024-08-26 08:21:52

如果您只是对最小化 CSS 文件的下载大小感兴趣,您可以使用众多可用的 CSS 压缩器之一(例如 这个 一个)。并且一定要对您的 javascript 文件执行相同的操作。

If you are just interested in minimizing the download size for your CSS file, you might use one of the many CSS compressors available (such as this one). And be sure to do the same with your javascript files while you are at it.

女中豪杰 2024-08-26 08:21:52

如果 CSS 颜色代码采用以下形式,则只能将它们缩短为 3 个字符版本

#XXYYZZ

然后它们可以缩写

#XYZ

只有 216 种不同的代码满足此要求。

You can only shorten CSS colour codes to a 3 character version if they take the form

#XXYYZZ

Then they can be abbreviated

#XYZ

There are only 216 different codes which meet this requirement.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文