开发者

CSS cleaner to "unfold" style sheets?

I'm looking for a web service or (OS X) software that will take a style sheet like this one:

h1,h2 {margin-botto开发者_运维问答m:1em;}
h2.special {color:red;text-align:justify;}
p {margin-bottom:1em;font-weight:bold; }

and transform it into this:

h1,h2,p {margin-bottom:1em;}
h2.special {color:red}
h2.special {text-align:justify;}
p {font-weight:bold;}

I.e., I need something that will take each unique attribute / value combination in a CSS file and then group all selectors that use it.

It seems to me that this is a trivial problem, but the only bit of “coding” I’m capable of is a bit of RegEx - seems that doesn’t give me a solution here.

Thank you.

Note:

I'm aware that this approach may not lead to (size) optimization. It's not for a live site/CSS, but to analyze and "weed out" unnecessarily complex style sheets. After that step, attributes will be grouped again.


Try this: http://www.cssoptimiser.com/optimize.php Although I'm not sure how converting h2.special {color:red;text-align:justify;} to

h2.special {color:red}
h2.special {text-align:justify;}

would be an improvement. But that optimizer did do the other part (margin-bottom).

Basically just google "CSS optimizer"


You can look at a CSS extension framework such as: http://lesscss.org/

It does not clean your CSS, but allows you to create cleaner CSS.


You could also have a look at Compass http://compass-style.org/. It's an ruby based CSS framework


I don't think I can suggest a solution to your actual question (I've given the question +1 because it's a good question, well asked, and without an obvious answer), but with regard to "weeding out" unnecessary styles, you could try the Dust Me Selectors Firefox plugin.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜