IE中多类CSS继承问题

发布于 2024-11-08 11:51:24 字数 916 浏览 0 评论 0原文

我有一个名为“.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:

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

避讳 2024-11-15 11:51:24

如果您的页面没有正确的文档类型声明,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文