Google 疯狂的 ID 和类命名约定
我只是在玩 Firebug 并编辑 Gmail 的 CSS 文件,我想编辑一个按钮,但该按钮的 div ID 是 :rj
。我相当确定 CSS 不允许在 中使用冒号,尤其是以 ID 和类名开头。所以我的猜测是这是一些高级的技巧。我不确定每个用户是否都像这样一致,但是 FWIW,该 ID 用于页面顶部的“搜索邮件”按钮。
有谁知道他们在做什么以及他们是如何做的?
I was just playing around with Firebug and editing Gmail's CSS file, and I wanted to edit a button, but the div ID for that button was :rj
. I am fairly certain that CSS does not allow colons in —and especially starting as—ID and class names. So my guess is this is some advanced trickery. I'm not sure if it's consistent like this for each user, but FWIW, the ID was for the "Search Mail" button at the top of the page.
Does anyone know what they are doing and how they are doing it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
过去,ID 对允许的内容非常严格,但对课程则没有那么严格。然而,HTML5 减少了对 ID 值的许多限制。
以下是一篇关于 HTML5 中允许使用 ID 和类的文章: http://mathiasbynens.be/notes /html5-id-class
足以让你头疼了。
编辑:
为了解决更多关于为什么 Google 使用看似随机的 ID 的问题,我确信他们使用的 ID 和类对他们的程序员来说非常有意义。
IDs used to be quite strict on what was allowed, not so much for classes. HTML5, however, has lessened a lot of the restrictions on what could be ID values.
Here's an article on the what's allowed for IDs and classes in HTML5: http://mathiasbynens.be/notes/html5-id-class
It's enough to make your head hurt.
EDIT:
To address more of your question about why Google is using a seemingly random ID, I'm sure the IDs and classes they are using make perfect sense to their programmers.
Google 只拥有一种浏览器,因此如果他们想要创建像 Firefox 这样跨浏览器兼容的 Web 应用程序,他们必须遵循与其他 Web 开发人员相同的标准和规则。也就是说,大多数现代浏览器在解析 html 时都非常宽松,因此虽然您的示例不是正确的 HTML 并且可能无法验证,但不会产生明显的负面影响。
Google only owns one browser so if they want to create a web app that is cross browser compatible like firefox they must follow the same standards and rules as every other web developer. That said most modern browsers are pretty lenient when it comes to parsing html so while your example is not correct HTML and probably wouldn't validate there would be no visible negative effects.