IE中多类CSS继承问题
我有一个名为“.spr”的类(用于图像精灵)和许多更改宽度、高度和背景位置属性以显示精灵的各个部分的类。
我还有“.on”类来在“开”或“关”状态下显示的图像之间切换。
问题是,在 IE 中,应与某个类关联的“on”类被应用于没有该关联类(而是不同的类)的按钮。
屏幕截图:
CSS:
.spr.burst.been {background-position: -241px -89px;
.spr.burst.on {
background-position: -301px -89px !important; }
.spr.radiobutton {background-position: -250px -249px; }
.spr.radiobutton.on {
background-position: -250px -218px;
border: 3px dashed red; }
尽你所能看,IE9 将该类解释
.spr.radiobutton.on
为
.spr.on
and ,因为它稍后出现在样式表中,因此覆盖 的属性,
.spr.burst.on
即使
.spr.burst
没有该类
.radiobutton
如何在 IE 中正确应用这些复合样式?
I have a class called ".spr" (for an image sprite) and many classes that alter the width, height and background-position attributes to show various parts of the sprite.
I also have ".on" classes to toggle between images appearing in an "on" or an "off" state.
The problem is that, in IE, the "on" class that should be associated with a certain class is being applied to a button that doesn't have that associated class (but a different one).
Screenshot:
The CSS:
.spr.burst.been {background-position: -241px -89px;
.spr.burst.on {
background-position: -301px -89px !important; }
.spr.radiobutton {background-position: -250px -249px; }
.spr.radiobutton.on {
background-position: -250px -218px;
border: 3px dashed red; }
As you can see, IE9 interprets the class
.spr.radiobutton.on
as
.spr.on
and, since it comes later in the stylesheet, overrides the properties of
.spr.burst.on
even though
.spr.burst
does not have the class
.radiobutton
How can I properly apply these composite styles in IE?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的页面没有正确的文档类型声明,IE9 将进入怪异模式并像 IE5/IE6 一样对待链式类选择器: 它只会读取最后一个类并相应地应用规则。
因此,选择器
.spr.radiobutton.on
实际上被解释为.on
(而不是.spr.on
),覆盖它认为也只有.on
选择器的早期规则。只需给您的文档提供一个文档类型声明,IE9 就会按预期运行。
If your page doesn't have a proper doctype declaration, IE9 will go into quirks mode and treat chained class selectors exactly like IE5/IE6 does: it'll only read the last class and apply rules accordingly.
As a result, the selector
.spr.radiobutton.on
is really being interpreted as just.on
(rather than.spr.on
), overriding the earlier rule that it thinks also has just the.on
selector.Simply give your document a doctype declaration and IE9 will behave as expected.