优化(删除冗余和合并)CSS 的工具?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12451354/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 20:10:43  来源:igfitidea点击:

Tools to optimize (remove redundancy and merge) CSS?

csscompressionminifyyui-compressor

提问by Lucian Povatanu

I'm searching for a good CSS compress, merge and optimization tool. I have found tools that clean the CSS but they don't optimize the overwrites.

我正在寻找一个好的 CSS 压缩、合并和优化工具。我找到了清理 CSS 但它们没有优化覆盖的工具。

Here is a basic example:

这是一个基本示例:

a{color:#000}

a{color:#000}

and on another line the acolor is overwritten with this:

在另一行,a颜色被这个覆盖:

a{color:#fff}

a{color:#fff}

Does anyone know of a tool that can clean the unused CSS, that was overwritten and keep just the applied style?

有谁知道可以清除未使用的 CSS 的工具,该工具已被覆盖并仅保留应用的样式?

回答by Whymarrh

I don't particularly understand what you mean by "clean unused CSS", but in any case, I'll throw two tools at you, and maybe one will work (the good ol' shotgun approach).

我不太明白你所说的“清理未使用的 CSS”是什么意思,但无论如何,我会向你扔两个工具,也许一个会起作用(好的 ol' 霰弹枪方法)。

CSS Lintseems to point out "duplicate properties". There are a rangeof articlescovering some of what it does. But a test with the two definitions you had,

CSS Lint似乎指出了“重复属性”。有一系列文章涵盖了它的一些功能。但是用你的两个定义进行测试,

a { color: #fff; }
a { color: #000; }

it didn't do much of anything. While ...

它没有做任何事情。尽管 ...

Code Beautifierdid combine the two selectors, opting for the latter of the two (i.e. the style that's actually applied). Resulting in:

Code Beautifier确实结合了两个选择器,选择了两者中的后者(即实际应用的样式)。导致:

a {
  color:#000;
}