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 Bolson15mo 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
JomuOP15mo ago
Would that be something like this? input:checked ~ has(body) { background: white; }
Chris Bolson
Chris Bolson15mo ago
It would need to be like this
body:has(input:checked){
background: white;
}
body:has(input:checked){
background: white;
}
Jomu
JomuOP15mo ago
Oh, yes that makes more sense. Thank you so much for the support, it worked!
Want results from more Discord servers?
Add your server