0

I want to target everything in the body except 2 classes

body {
 background: gray;
}

What I am try:

body:not(.myCustomClassWhereIsBackgroundWhite)  {
     background: white;
}

My angular component Profile:

<div class="myCustomClassWhereIsBackgroundWhite"> 
 ...other context
 </div>

In this component is not affected background: white;

This is no work ? Please provide me some solution ? I want to some class to change and not be background gray

Sosauls
  • 1
  • 4
  • `body :not(.myCustomClassWhereIsBackgroundWhite)` - note the space – Paulie_D Sep 23 '21 at 10:11
  • right now background: gray; is not affected... weird – Sosauls Sep 23 '21 at 10:15
  • Does this answer your question? [Can I write a CSS selector selecting elements NOT having a certain class or attribute?](https://stackoverflow.com/questions/9110300/can-i-write-a-css-selector-selecting-elements-not-having-a-certain-class-or-attr) – Donald Duck Sep 23 '21 at 11:08

1 Answers1

1

body:not(.myCustomClassWhereIsBackgroundWhite) targets body elements which donot have class myCustomClassWhereIsBackgroundWhite.

Reference

If you want to look elements inside body, you have to add a space like.

body :not(.myCustomClassWhereIsBackgroundWhite)

body {
  background: gray;
}

body :not(.myCustomClassWhereIsBackgroundWhite) {
  background: white;
}
<div class="myCustomClassWhereIsBackgroundWhite">
  ...other context
</div>
<div>
  Some other element
</div>
Nitheesh
  • 19,238
  • 3
  • 22
  • 49
  • NO work. Here is problaby problem with angular components,, – Sosauls Sep 23 '21 at 10:23
  • @Sosauls which version of angular are you using? – Nitheesh Sep 23 '21 at 10:26
  • using angular 9 ivy – Sosauls Sep 23 '21 at 10:31
  • this is no work ..body :not(.myCustomClassWhereIsBackgroundWhite) { background: white; } Right now all body is white ? – Sosauls Sep 23 '21 at 10:33
  • ohh, right now work but remember old values on all page. Example background is gray. I go to page where need to be white background and it work... but stay background white for others page...and when i refresh it be again good ? – Sosauls Sep 23 '21 at 10:38
  • Are you undarstand or i need to better explain ? in short. All pages are ok for me. I come to a page where there should be a gray background and it works. I go to another page where there should be no more gray background but the body remembers the old value ( css value) – Sosauls Sep 23 '21 at 10:43
  • @Sosauls you have to handle in the individual components then. – Nitheesh Sep 23 '21 at 10:48
  • Probably but how ? What ? – Sosauls Sep 23 '21 at 10:54
  • friend here is problem body ... I am add new tag on some component but i need to change body ...not that component ... – Sosauls Sep 23 '21 at 12:05