Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS cleaner to "unfold" style sheets?

Tags:

css

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

h1,h2 {margin-bottom: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.

like image 924
Wintermute101 Avatar asked Oct 10 '22 18:10

Wintermute101


1 Answers

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"

like image 168
AR. Avatar answered Oct 14 '22 01:10

AR.