Harsha
Harsha

Reputation: 1181

Extract only used css classes from css file

I'm working on an upgrade for our current application (asp.net mvc). Here my problem is, I have a existing css file name "styles.css". Now this file has lots of css classes and they are used in different pages.

Now as a part of the upgrade process, this css file will not be used anymore. But I still want certain css classes from this file, so that I can copy them to a new file and include it in my pages.

Any ideas on how to extract these styles which are used in my new pages. And yes the styles which I want to pick are already set to the controls in the page. Please help.

Upvotes: 9

Views: 8056

Answers (4)

Meligy
Meligy

Reputation: 36624

Finding ones that are used in single page should be easy with multiple tools. One good tool is called UnCSS.

The trick is checking an entire site where CSS file is shared accross pages.

This approach was popular in social networks recently with some high profile guys sharing it like Google's Addy Osmani and some Google Chrome guys:

http://addyosmani.com/blog/removing-unused-css/

Upvotes: 10

Adel
Adel

Reputation: 1468

There are a lot of ways, for example:

Upvotes: 1

alpham8
alpham8

Reputation: 1362

Use a Browser Debugger, click on the elements on site and see on the right corner which classes are machtes and copy them.

Upvotes: -1

zero298
zero298

Reputation: 26920

Use Chrometools Audits

In Chrome Press: F12 -> Audits -> Run

It will let you know what is and is not used.

Chrome Audits

Upvotes: 6

Related Questions