CSS选择器与空声明 - 浏览器仍然搜索? [英] CSS Selectors with empty Declaration - will the browser still search?

查看:112
本文介绍了CSS选择器与空声明 - 浏览器仍然搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说明样式表中没有样式信息的选择器,因此它们实际上为空(没有样式声明):

Say there are selectors in a stylesheet that have no style info in them, so they are effectively empty (have no style declarations):

.main-menu {}

浏览器仍然会搜索它们吗?

Will the browser still search for them?

我的直觉是,它将取决于浏览器,所以一个智能程序员会说如果选择器空不打扰,但不是所有的浏览器都会有这种开明的实施。如果有一个快速搜索,并找不到任何东西,想知道是否有人知道这里的任何人...

My gut feeling is that it will depend on the browser, so an 'intelligent' programmer would say 'if selector empty don't bother' but not all browsers will have this kind of enlightened implementation. Had a quick search and couldn't find anything, was wondering if anyone on here knew anything regarding this...

最好的做法我肯定是没有选择器有空的声明,因为它们是浪费空间和时间,W3是否对此有所说明?

Best practice i'm sure is to not have selectors with empty declarations, as they are a waste of space and time, does W3 say anything about this?

谢谢!

推荐答案

事实上,有空的CSS规则实际上可以服务解决某些浏览器中的某些错误 导致其他人的错误。因此有证据表明,对于至少两个独立的实现,解析器不会直接忽略具有空声明块的CSS规则。

As a matter of fact, having empty CSS rules can actually serve to work around some bugs in certain browsers, and cause bugs in others. So there is evidence to suggest that, for at least two independent implementations anyway, the parser does not outright ignore CSS rules with empty declaration blocks.

对于最佳实践?离开它们,因为他们通常会做的是占用不必要的字节,如果你有一个很好的理由使用它们,添加一个注释解释他们的目的是一个坏主意。

As for best practice? Leave them out as all they would normally do is take up unnecessary bytes, and if you have a very good reason to use them, it's not a bad idea to add a comment explaining their purpose.

这篇关于CSS选择器与空声明 - 浏览器仍然搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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