IE8 不接受怪异模式下的多个类?

发布于 2024-08-09 22:35:16 字数 414 浏览 13 评论 0原文

我遇到了 IE8 似乎正在删除 CSS 选择器的情况。我觉得这很难相信,但我无法弄清楚发生了什么。

在 .css 文件中,我有这样的声明:

#srp tr.objectPath.hover td {
    border-top:none;
}

但是,当我通过内置开发人员工具检查 IE8 中的文件时,声明被修改为:

#srp TR.hover TD {
    border-top:medium none;
}

我不关心大小写的更改或规则的重述,但删除“.objectPath”是一个真正的问题,因为它针对的规则比我预期的更广泛。

我注意到这个页面是并且必须保持在 Quirks 模式。

有什么想法吗?

谢谢!

I'm running into a situation where IE8 appears to be dropping CSS selectors. I find this hard to believe, but I can't figure out what is happening.

In a .css file I have this declaration:

#srp tr.objectPath.hover td {
    border-top:none;
}

However, when I inspect the file in IE8 through the built-in developer tools, the declaration is modified to this:

#srp TR.hover TD {
    border-top:medium none;
}

I don't care about the change in case or the restatement of the rule, but dropping the '.objectPath' is a real problem because it targets the rule more broadly than I intend.

I note that this page is, and must stay in, Quirks mode.

Any ideas what is happening?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

怀中猫帐中妖 2024-08-16 22:35:16

在 Quirks 模式下,IE 8 呈现页面并将 DOM 视为 IE 5.5 呈现的方式。这就是 Quirks 模式下的 IE 8 忽略多个类的原因。这不是 IE 8 中的错误,如果您希望正确解析和呈现页面,那么您必须设置正确的 DOCTYPE 以在标准模式下呈现页面。

In Quirks Mode IE 8 renders the page and treats the DOM as IE 5.5 would render. That's the reason IE 8 in Quirks Mode ignores the multiple classes. It is not a bug in IE 8, if you want your page to be parsed and rendered properly, then you must have a proper DOCTYPE set to render the page in Standards Mode.

拥抱影子 2024-08-16 22:35:16

如果您尝试使用 hover 伪类,则 tr.objectPath.hover 不是正确的语法。正确的语法是使用冒号(即tr.objectPath:hover)。当机器读取您的代码时,它会将 objectPath 读取为 tr 的类名,但当它到达 hover 时,它就会消失旧类名并将其替换为 hover 类(无论实际上是否有任何元素属于该类。另外,如果是这种情况,那么我看不出你是什么尝试通过引用 :hover 实例的子级来完成,

如果您实际上使用 hover 作为类名(我不推荐这样做,因为它可以)让阅读代码的人感到困惑),并且您希望 CSS 应用于 trtd 子级,该 tr 属于 objectPath 和 考虑为两个类的元素创建一个新类并使用它(即#srp tr.newClass td )。

hover 类,您可能会 编辑:进一步研究此事,似乎这是(还)一个(另一个)IE 中的已知错误。我已经在IETester中测试过了,它似乎存在于所有版本的IE中。我在你这边看到的唯一解决方案非常非常混乱:

首先,它需要在 CSS 中使用 JavaScript,因为你无法访问其他任何东西。这是可能的,但很容易出现错误

其次,需要在该 JavaScript 中创建一个 getElementsByClass 函数,该函数可以采用多个类名作为参数。这将是一个非常大的代码块

最后,您可能希望考虑将此代码指定为 仅由 IE 使用,这样其他浏览器的用户就不必处理所有这些东西带来的任何潜在问题。

澄清一下,我不建议这样做。相反,我建议联系那些有权访问 HTML 源代码的人(假设您实际上正在与他们合作),以便他们可以应用更简单的修复方法,将 objectPathhover 类添加到属于两个类甚至属于它们的 td 子类的 tr 元素。

tr.objectPath.hover is not correct syntax if you are trying to use the hover pseudo-class. The correct syntax would be with a colon (ie tr.objectPath:hover). When the machine is reading your code, it reads objectPath as the tr's class name, but then when it gets to hover it gets rid of the old class name and replaces it with the hover class (whether there are actually any elements belonging to that class or not. Also, if this is the case, then I don't see what you are trying to do by referring to the child of an instance of :hover.

It you are in fact using hover as a class name (which I wouldn't recommend as it could be confusing to people reading your code) and you want the CSS to apply to the td children of a tr that is of both the objectPath and hover classes, you might consider just creating a new class for elements that are of both classes and using that instead (ie. #srp tr.newClass td).

EDIT: Looking further into the matter, it appears that this is (yet) a(nother) known bug in IE. I have tested it out in IETester and it seems to exist in all versions of IE. The only solution I could see on your end is very very messy:

First, it would require using JavaScript in your CSS since you don't have access to anything else. This is possible but very prone to bugs.

Second, it would require creating a getElementsByClass function in that JavaScript that could take multiple class names as parameters. This would be a very sizable chunk of code.

Finally, you would probably want to look into specifying this code to be used only by IE so that users of other browsers don't have to deal with any potential problems from all this stuff.

To clarify, I would NOT recommend doing this. Instead, I would suggest contacting someone who does have access to the HTML source code (assuming you are actually working in partnership with them) so that they could apply the much simpler fix of adding an objectPathhover class to the tr elements that belong to both classes or even to their td children.

深海夜未眠 2024-08-16 22:35:16

看起来您的声明中存在一些不正确的语法,但很难准确说出您在做什么。您是否正在尝试匹配悬停状态,或者是否有一个实际上称为“悬停”的类?

如果要获取状态,请尝试:

#srp tr.objectPath:hover td {
    ...
}

如果有另一个类,您可能需要 2 个单独的声明:

#srp tr.objectPath td {
    ...
}

#srp tr.hover td {
    ...
}

It looks like you've got some incorrect syntax in your declaration, but its hard to tell exactly what you're doing. Are you trying to match to a hover state or is there a class actually called 'hover' ?

If going for the state, try:

#srp tr.objectPath:hover td {
    ...
}

If there is another class, you may need 2 separate declarations:

#srp tr.objectPath td {
    ...
}

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