有没有办法检查网页上正在使用或未使用哪些 CSS 样式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4361007/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:16:20  来源:igfitidea点击:

Is there a way to check which CSS styles are being used or not used on a web page?

css

提问by HELP

Want to know which CSS styles are currently being used on a web page.

想知道当前在网页上使用了哪些 CSS 样式。

采纳答案by kobe

Install the CSS Usage add-onfor Firebug and run it on that page. It will tell you which styles are being used and not used by that page.

安装Firebug的CSS Usage 插件并在该页面上运行它。它会告诉您该页面正在使用和未使用哪些样式。

回答by Cordell

Google Chrome has a two ways to check for unused CSS.

谷歌浏览器有两种方法来检查未使用的 CSS

1. Audit Tab:> Right Click + Inspect Element on the page, find the "Audit" tab, and run the audit, making sure "Web Page Performance" is checked.

1. 审计选项卡:> 右击 + 检查页面元素,找到“审计”选项卡,运行审计,确保选中“网页性能”。

Lists all unused CSS tags- see image below.

列出所有未使用的 CSS 标签- 见下图。

Screen Shot of Chrome's Audit Tool

Chrome 审计工具的屏幕截图

Update:- - - - - - - - - - - - - - OR - - - - - - - - - - - - - -

更新:- - - - - - - - - - - - - 或 - - - - - - - - - - - - -

2. Coverage Tab:> Right Click + Inspect Element on the page, find the three dots on the far right (circled in image) and open Console Drawer (or hit Esc), finally click the three dots left side in the drawer (circled in image) to open Coverage tool.

2. Coverage Tab:> 右击 + Inspect Element 在页面上,找到最右边的三个点(图中圈出的)并打开 Console Drawer(或按 Esc),最后点击抽屉左侧的三个点(圈出)在图像中)打开 Coverage 工具。

Chrome launched a tool to see unused CSS and JS - Chrome 59 UpdateAllows you to start and stop a recording (red square in image) to allow better coverage of a user experience on the page.

Chrome 推出了一个工具来查看未使用的 CSS 和 JS - Chrome 59 更新允许您开始和停止录制(图像中的红色方块)以更好地覆盖页面上的用户体验。

Shows all used and unused CSS/JS in the files- see image below.

显示文件中所有使用和未使用的 CSS/JS- 见下图。

Example of Coverage tool in Chrome

Chrome 中的 Coverage 工具示例

回答by Jan Petzold

Just for completeness and because it was asked in the comments - there's also the CSS audit tool in Chromenow for the same purpose. Some details here:

只是为了完整性,并且因为它在评论中被问到 -现在Chrome 中也有 CSS 审计工具用于相同的目的。一些细节在这里:

http://meeech.amihod.com/very-useful-find-unused-css-rules-with-google

http://meeech.amihod.com/very-useful-find-unused-css-rules-with-google

回答by Robert Brisita

Take a look at UnCSS. It helps in creating a CSS file of used CSS.

看看UnCSS。它有助于创建一个使用过的 CSS 的 CSS 文件。

回答by cs.matyi

I'm using CSS Dig. It is made for chrome, but I think it is a great tool!

我正在使用CSS Dig。它是为 chrome 设计的,但我认为它是一个很棒的工具!

回答by Shashwat Sahai

Try using this tool,which is just a simple js script https://github.com/shashwatsahai/CSSExtractor/This tool helps in getting the CSS from a specific page listing all sources for active styles and save it to a JSON with source as key and rules as value. It loads all the CSS from the href links and tells all the styles applied from them You can modify the code to save all css into a .css file. Thereby combining all your css.

尝试使用此工具,它只是一个简单的 js 脚本https://github.com/shashwatsahai/CSSExtractor/此工具有助于从列出所有活动样式源的特定页面获取 CSS,并将其保存到 JSON 中,源为键和规则作为值。它从 href 链接加载所有 CSS 并告诉从它们应用的所有样式您可以修改代码以将所有 css 保存到 .css 文件中。从而结合你所有的css。