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
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.
Would that be something like this?
input:checked ~ has(body) {
background: white;
}
It would need to be like this
Oh, yes that makes more sense. Thank you so much for the support, it worked!