Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS html * except some class?

Tags:

html

css

I want to apply this to everything except a specific class and its children

html * {

 box-shadow: none !important;
 border: none !important;
 color: white;

     }

I tried this but not working

html *:not(.myclass *) {

 box-shadow: none !important;
 border: none !important;
 color: white;

     }
like image 500
Slown1970 Avatar asked Jan 01 '23 19:01

Slown1970


2 Answers

Not a direct answer to what you are asking, but is it not better to potentially have this:

html * {    
 box-shadow: none;
 border: none;
 color: white;
}

And then override it specifically in those classes where it is wanted, e.g.

.myclass {
    color:blue;
}

This is more how you might expect to find it. Note that I removed the 'important' declarations from the first * specifier as this makes things more difficult to potentially override in the future.

like image 134
Paddy Avatar answered Jan 03 '23 08:01

Paddy


just add the :not(.myclass) selector between the body and the * and the selector :not again after the *:not(.myclass)

body :not(.myclass) *:not(.myclass) {
       box-shadow: none !important;
       border: none !important;
       color: red;
    }
<div>
  <h1>test 1</h1>
</div>

<div class="myclass">
  <h1 class="myclass">test 2</h1>
</div>

<div class="myclass">
  <h1>test 3</h1>
</div>

<div>
  <h1 class="myclass">test 4</h1>
</div>
like image 34
Lucas Avatar answered Jan 03 '23 09:01

Lucas