“.class”和“.class”之间的区别和“* html .class”和“html>body.class”
我研究过 Google Docs 的 css 样式,我注意到有这样的事情:
.goog-inline-block {
position : relative;
display : -moz-inline-box;
display : inline-block
}
* html .goog-inline-block {
display : inline
}
*:first-child + html .goog-inline-block {
display : inline
}
html>body .goog-inline-block {
display : -moz-inline-box;
display : inline-block
}
我理解这个 .goog-inline-block
类应该意味着什么,但是这段代码给我带来了问题:
- 为什么一个简单的类有这么多声明?
- 为什么简单的
.class-name
声明与* html .class-name
声明不同? - 这个狡猾的构造
*:first-child + html .class-name
是做什么的?
I've studied css styles of Google Docs, and I have noticed there such a thing:
.goog-inline-block {
position : relative;
display : -moz-inline-box;
display : inline-block
}
* html .goog-inline-block {
display : inline
}
*:first-child + html .goog-inline-block {
display : inline
}
html>body .goog-inline-block {
display : -moz-inline-box;
display : inline-block
}
I understand what this .goog-inline-block
class should mean, but this code arose questions for me:
- Why are there so much declarations for a simple class?
- Why does simple
.class-name
declaration differ from* html .class-name
declaration? - What is this crafty construction
*:first-child + html .class-name
doing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该规则:
定义了IE6的样式。在 IE6 的文档模型中,有一个神秘的根元素包含
html
,因此该选择器使用* html
hack 来利用这一事实。该规则:
定义了IE7的样式。在 IE7 的文档模型中,above
html
不再有根元素,但之前还有另一个根元素,这就是的目标元素*:first-child + html
选择器。该规则:
定义IE7+及其他浏览器的样式。 IE6 不支持子选择器
>
,因此它永远不会看到此规则。-moz-inline-box
实际上与inline-block
相同,但适用于 Firefox 2 及更早版本,因为这些版本不支持inline-block< /代码>。
该类有如此多的声明,因为不同的浏览器在
display: inline-block
样式方面存在问题,因此需要针对这些浏览器进行修改和解决方法。This rule:
defines a style for IE6. In IE6's document model, there's a mysterious root element that contains
html
, so this selector takes advantage of that fact using the* html
hack.This rule:
defines a style for IE7. In IE7's document model, there's no more root element above
html
, but there's another one before it, which is what's targeted by the*:first-child + html
selector.This rule:
defines styles for IE7+ and other browsers. The child selector
>
isn't supported by IE6, so it never sees this rule.-moz-inline-box
is actually the same asinline-block
, but meant for Firefox 2 and older as those versions don't supportinline-block
.There are so many declarations for that class because different browsers have problems with the
display: inline-block
style, so hacks and workarounds are needed for these browsers.