Grow your CSS skills. Land your dream job.

[Solved] CSS Cleanup

  • # April 4, 2008 at 5:17 pm

    Hi all,

    sometimes I add a lot of classes to my css files and then end up not using all of them. I then manually go throug the lines and look for classes that I remember not using.

    I was just thinking, is there a tool where I can just enter my website adress and the css file and it checks which classes are used and which are not? A quick google search only brought up a loot of tools that help formatting the code, what is not my problem.

    # April 4, 2008 at 5:54 pm

    I used to know of a website that did this, but looking back through some things, all I can find are things that automatically tab it for aesthetics or remove line breaks, etc.

    # April 4, 2008 at 7:00 pm

    I’m straining my brain trying to think of a site that did this too, but I just can’t seem to remember!

    There might be a "manual" solution. For any class that you think you don’t need any more, go in and add something like "border: 10px solid red;". Then go refresh your page. I think you’ll see if you are using it or not ;) . Make sure you check all pages that the CSS files is applied to. If nothing has a giant red border, delete that class and move on to the next.

    # April 4, 2008 at 7:22 pm

    I’ve known the same problem… Nice creative solution Chris :D

    # April 7, 2008 at 3:00 pm

    thanks to you guys… Well if someone finds a solution for this, please let me know! Chris’ solution could be a bit stressful on a 1000-line css file. (which seems wrong in the first place but still exists…)

    Maybe I have time one day to code a tool like that myself. Maybe! :D

    (Btw: I didn’t get a mail for your replies, maybe it got caught by my gmail spam filter? I ticked the box "notify me when a reply posted…)

    dag
    # April 7, 2008 at 4:01 pm
    "Michael" wrote:
    …formatting the code, what is not my problem…

    Hi Michael, I may not have understood your problem, but I believe that code beautifier could be useful.

    PS: Sorry if I do not write good, but I am Italian and I do not write well in English

    # April 7, 2008 at 6:24 pm
    "dag" wrote:
    "Michael" wrote:
    …formatting the code, what is not my problem…

    Hi Michael, I may not have understood your problem, but I believe that code beautifier could be useful.

    PS: Sorry if I do not write good, but I am Italian and I do not write well in English

    Hi Dag and Greetings to Italy. I am actually from Germany, so aaalmost a neighbour ;-)

    Thanks for the link but that is not really what I am looking for. Something like that but with the possibility to give the tool a web page and then have it checked for which css classes are never referenced. (Kind of like a garbage collector for css)

    # April 7, 2008 at 7:33 pm

    Really cool to be here together from all over the world :)
    Back to the problem: I think it is possible to make such a css-checker yourself by using php.
    Here is the theory:

    1. First you have to put all your xhtml-codes into one variable.
    2. Copy all your css-rules to a new file and clean it up so you only have the class- and id-names left.
    3. Put those class- and id-names into an array
    4. Make a loop with there in the function strstr() to check if the current class/id-name is into the variabele.
    5. Print all the class- and id-names which aren’t found in the variable.

    I know it’s a lot of work, but it’s much faster then checking everything manually. And besides that, once you’ve build this script, you can use it on other sites too. :idea: Good luck! ;)

    # April 9, 2008 at 4:26 pm

    I remember using a firefox add-on that searched for unused CSS classes, but since I rarely used it, I removed it and now I don’t remember the name.

    # April 9, 2008 at 4:58 pm

    Just one try at Google: brought me to: http://www.sitepoint.com/dustmeselectors/

    # April 11, 2008 at 4:19 pm
    "Edwin" wrote:

    I was just going to recommend that myself. I’ve been looking for something like that for forever and finally came across it about a week ago. Fantastic tool!

    # April 11, 2008 at 6:22 pm
    "Edwin" wrote:

    Awesome! thanks a lot, I will check that one out, but it sounds like the one thing I was looking for. Thanks!

    # April 11, 2008 at 6:59 pm

    I didn’t test it myself, but if it really works, it’s a lot easier then the whole php-plan ;)
    So I would say: give it a try and tell if it worked like you wished it would :)

    # October 5, 2009 at 9:26 pm

    Thank you for helping guys… This is something for a newbie in CSS like me… looking forward to new tips and tricks from you. Thanks Guys! :D

Viewing 14 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".