查找丢失的CSS类和ID的最简单方法 [英] easiest way to find missing css classes and ids

查看:63
本文介绍了查找丢失的CSS类和ID的最简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何识别代码中引用但css文件中缺少的css类或ID?我可以使用Firebug中的任何功能吗?

How can I identify css classes or ids that are referenced in code but missing in the css file? Is there any feature in firebug that i can use?

谢谢.

推荐答案

Firebug不会执行此操作,也不提供我能想到的任何工具,因为它不是常见的或高回报的任务.

Firebug does not do this, nor any tool I can think of, because it is not a common or high-payback task.

但是, 是查找未使用的CSS规则以便对其进行修整的常见任务.您可以通过修剪常见的CSS文件来获得性能提升.但是,从HTML页面中删除ID和类没有太大帮助,并且更有可能破坏某些内容(请参见下文).

However, it is a common task to find unused CSS rules, so that they can be trimmed. You can get a performance gain by trimming common CSS files. But removing ID's and classes from HTML pages does not help as much, and is more likely to break something (see below).

我选择的灰尘 .如果您确实想要一种工具来查找没有CSS规则的ID和类,则可以采用

A good/common Firefox add-on for finding unused CSS rules, is Dust-Me Selectors. If you really want a tool to find ID's and classes that don't have CSS rules, you could probably take that add-on's source code as a good starting point for making your own Firefox extension.

删除ID和类(仅因为它们没有CSS规则)不是一个好主意,并且可能会破坏事情.
出于多种原因,ID和类可以出现在页面中,而不仅仅是CSS的便捷句柄.

Removing ID's and classes, just because they don't have a CSS rule is not a good idea and could break things.
ID's and classes can be in a page for a variety of reasons, not just as convenient handles for CSS.

以下是ID或类可能出现在页面中的一些原因:

Here are some reasons why an ID or class might be in a page:

  1. 使用javascript标识内容,或标记要更改内容的目标.除了最简单的动态页面,这对于所有页面都是必须的.
  2. 同样,插件和扩展,蜘蛛网,RSS工具等使用ID和类.
  3. 作为状态或状态指示符. EG:<p class="comment highest-rated">...
  4. 可轻松替代页内定位符.这些允许精确定位的超链接而无需添加元素. 示例链接.
  5. 作为良好语义标记的一部分,是一种最佳做法,可以帮助人们和我们的脚本理解,使用和维护页面.
  6. 以帮助定位CSS.
  1. To identify content to javascript, or mark targets for changing content. This is a must for all but the simplest dynamic pages.
  2. Likewise, Id's and classes are used by plugins, extensions, spiders, RSS tools, etc.
  3. As state or status indicators. EG: <p class="comment highest-rated">...
  4. As easy substitutes for in-page anchors. These allow precisely-targeted hyperlinks without adding elements.   Example link.
  5. As part of good Semantic Markup, which is a best-practice that helps humans and our scripts understand, use, and maintain pages.
  6. To help with targeting CSS.

这篇关于查找丢失的CSS类和ID的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆