In brief: Achieving this purely with CSS is not currently possible, but...
Diving deeper:
There exists a pseudoclass called :has()
that can target elements with specific attributes. In your scenario, it might look something like: body:has(div a:hover)
.
Unfortunately, this feature has limited support at present.
Nevertheless, there is an alternative solution using HTML <input>
and <label>
elements except for the inability to alter the background-color
of the <body>
element due to its auto-generated start tag by the browser even before other nested elements are written regardless of the placement in the code.
HTML:
<body>
<input id="magic" type="checkbox">
<div>
<label for="magic"><a href="#">Link</a></label>
</div>
</body>
CSS:
html, body, div {
margin: 0;
height: 100%;
}
#magic:hover + div {
background: red;
}
input {
position: fixed;
left: -100%;
}