Html IE 中 colspan > 1 的 td 元素的 CSS 规则

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11783929/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:01:56  来源:igfitidea点击:

CSS rules for td elements with colspan > 1 in IE

htmlcsscss-selectors

提问by Erik

I need to apply some css styles to td elements which have 'colspan' attribute and its value greater than 1.

我需要将一些 css 样式应用于具有“colspan”属性且其值大于 1 的 td 元素。

I do the following:

我执行以下操作:

td[colspan][colspan!=1] {
 background: red;
}

It works all browsers instead IE (include latest). Please help. How can I fix that.

它适用于所有浏览器而不是 IE(包括最新版本)。请帮忙。我该如何解决。

回答by BoltClock

That is not supposed to work in any browser because [colspan!=1]is not a valid CSS attribute selector. It only exists in jQuery as a non-standard extension.

这不应该在任何浏览器中工作,因为[colspan!=1]它不是有效的 CSS 属性选择器。它仅作为非标准扩展存在于 jQuery 中。

From the jQuery documentation:

jQuery 文档

This selector is equivalent to :not([attr="value"]).

此选择器等效于:not([attr="value"]).

This means for it to work in CSS you need to use this instead:

这意味着要在 CSS 中工作,您需要使用它:

td[colspan]:not([colspan="1"]) {
 background: red;
}

Remember that :not()isn't supported by IE older than version 9. If you need to support older browsers, you can either use jQuery to apply the styles, or if you must use CSS then you should override the styles for your tdelements with [colspan="1"]instead:

请记住,:not()版本 9 之前的 IE 不支持。如果您需要支持旧浏览器,您可以使用 jQuery 来应用样式,或者如果您必须使用 CSS,那么您应该使用以下方式覆盖td元素的样式[colspan="1"]

td {
 background: red;
}

td[colspan="1"] {
 background: transparent;
}