如何为除一个类之外的所有元素创建一个 css 规则?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2489674/
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 21:46:02  来源:igfitidea点击:

How to create a css rule for all elements except one class?

csscss-selectors

提问by Nick

I have created a CSS stylesheet for my project. Is there any way I can create a css rule that applies to all table elements EXCEPT table elements belonging to the class "dojoxGrid"? Something like:

我为我的项目创建了一个 CSS 样式表。有什么方法可以创建适用于所有表格元素的 css 规则,除了属于“dojoxGrid”类的表格元素?就像是:

.not(dojoxGrid) table{
    width:100%;
    border-top:1px solid #dddddd;
    border-left:1px solid #dddddd;
    border-right:1px solid #dddddd;
    margin:1em auto;
    border-collapse:collapse;
}

回答by Knu

The negation pseudo-classseems to be what you are looking for.

否定伪类似乎是你在找什么。

table:not(.dojoxGrid) {color:red;}

It's not supported by ≤ IE8 though.

但 ≤ IE8 不支持

回答by cori

Wouldn't setting a css rule for all tables, and then a subsequent one for tables where class="dojoxGrid" work? Or am I missing something?

不会为所有表设置一个 css 规则,然后为 class="dojoxGrid" 工作的表设置一个后续规则?或者我错过了什么?

回答by Joel

The safest bet is to create a class on those tables and use that. Currently getting something like this to work in all major browsers is unlikely.

最安全的选择是在这些表上创建一个类并使用它。目前不太可能在所有主要浏览器中使用这样的东西。