Body tag not working

I tried selecting the body tag, to change the background color when the button is checked, I couldn't figure out why the body tag doesn't change. When I added a div, it worked on the div. https://codepen.io/aldous-waites/pen/RwEQqQE
4 Replies
Chris Bolson
Chris Bolson17mo ago
The input is a child of the body. Your div was probably a sibling and that is why it worked. You can achieve this by using the has() selector but bear in mind that it isn’t fully supported.
Jomu
JomuOP17mo ago
Would that be something like this? input:checked ~ has(body) { background: white; }
Chris Bolson
Chris Bolson17mo ago
It would need to be like this
body:has(input:checked){
background: white;
}
body:has(input:checked){
background: white;
}
Jomu
JomuOP17mo ago
Oh, yes that makes more sense. Thank you so much for the support, it worked!

Did you find this page helpful?