I would like to set up my page so that when the user hovers over a link in a div, the color of the body background is changed, but only while hovering. This is the css
Short answer: It's not possible to do so in pure CSS yet, however...
Long answer:
There's a pseudoclass :has()
that can select element, that has specific properties. In your case it would be something like this: body:has(div a:hover)
.
Unfortunatelly, it has no support yet.
However it's possible to do so using HTML and
elements except you can't change
background-color
of element, because
start tag is generated automatically by the browser before any element that should be inside it no matter where in code it's actually written.
HTML:
CSS:
html, body, div {
margin: 0;
height: 100%;
}
#magic:hover + div {
background: red;
}
input {
position: fixed;
left: -100%;
}