JSFiddle example
For this method, I created a container element of a fixed position of static size with one child element inside it, occupying 200px by 200px.
Then I added two absolutely positioned elements ( .glass1 and .glass2 ) to simulate glass panels (“You can watch, but you cannot touch”), and I used z-index on them so that they cover the remaining space of the container element.
Adding these glass panes is to simulate the effect of nothing happening if you do not hover over the child. Otherwise, this method will not mimic the behavior of the parent selector; it will be just a normal implementation :hover .
At this point, it is just a matter of adding a property :hover to the container that did not affect the area covered by the child.
.container { background: lavender; top: 0; left: 0; position: absolute; width: 600px; height: 400px; z-index: 0; border: 1px solid black; } .glass1 { width: 400px; height: 200px; position: absolute; left: 200px; top: 0; z-index: 2; } .glass2 { width: 600px; height: 200px; position: absolute; z-index: 3; top: 200px; left: 0; } .hover { background: lightblue; width: 200px; height: 200px; margin: 0; position: absolute; } .container:hover:not(.hover) { background: seagreen; }
<div class="container"> <div class="hover">Hover over me. Change my parent.</div> </div> <div class="glass1"></div> <div class="glass2"></div>
The obvious problem with this implementation is its static nature and lack of reaction. A more practical hand may allow some degree of responsiveness.
Edit: More efficient version from ZachSaucier
source share