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

CssCss Selectors

Css Problem Overview


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:

.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;
}

Css Solutions


Solution 1 - Css

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

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

It's not supported by ≤ IE8 though.

Solution 2 - Css

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?

Solution 3 - Css

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNickView Question on Stackoverflow
Solution 1 - CssKnuView Answer on Stackoverflow
Solution 2 - CsscoriView Answer on Stackoverflow
Solution 3 - CssJoelView Answer on Stackoverflow