Tool to parse and compare two CSS stylesheets [closed]

喜欢而已 提交于 2019-11-30 10:19:49

问题


Does anyone know of a good tool that can parse and compare two CSS stylesheets in order to find which selectors have different styles?

I cannot use a standard diff-like tool because the two CSS files have very different layout. I need a tool that can parse and understand the CSS, then look for selectors that actually have different styles in the two stylesheets.

The only tool I've found is the CSS Comparer from Alan Hart, however it gets confused when there are styles that apply to multiple selectors.


回答1:


Here's what I ended up doing, in case someone else has the same problem:

  1. I used CSSTidy to "normalize" the two stylesheets I wanted to compare. Normalization in my case meant splitting multiple selectors and sorting selectors and properties. An online version of CSSTidy is available here.
  2. After this, I used the CSS Comparer tool from Alan Hart to find out differences between the two stylesheets.

This did the job for my specific requirements.




回答2:


I tried using CSS Compare. It seems to do exactly what you are looking for. However, it seems to have some issues with multiple selectors. The nice part is that it is command-line driven, so you can set up an automated process if you have lots of CSS files, or you can chain the CSS files together to compare them to one giant resultant SASS file. This tool will show you all the differences, including differences in the values of the classes.

What would be really nice if a tool showed you which styles overrode other styles in the same stylesheet. Many old sites have lots of baggage in this way and filtering it out would be great. Of course, an automated tool might cause issues, but at least something that generates a report like Firebug does, except for every selector and for the entire collection of CSS files, would be great. Sadly CSS Compare is not such a tool, and I don't know of one:(




回答3:


I would load up the webpage using one stylesheet in one tab and the other stylesheet in a different tab. Then use the inspector or firebug to check the style of pertinent nodes.

That's very manual, obviously, but what you ask is such a bandaid for a broken process that you probably won't find much help.

If you have some programming experience, you could probably write a parser yourself fairly easy that reports each defined class and its style. However, that is likely more work then it is worth.

Do it manually once, then fix the problem by moving to SASS ( http://sass-lang.com/ ) and putting better organization around your websites.



来源:https://stackoverflow.com/questions/7930064/tool-to-parse-and-compare-two-css-stylesheets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!