If you cannot change the layout, you cannot target the first menu item and hide it when the .widget child freezes. You will need to use JS.
I can not use JS, you will need to change your makup, you can achieve two goals:
Put the first .menu after the child .widget so that you can configure it with the .widget:hover > .widget:hover + .menu when the child widget hangs:
.widget { width: 500px; height: 500px; position: relative; background-color: #eee; } .widget > .widget{ left: 200px; top: 200px; width: 150px; height: 150px; background-color: #ddd; } .menu { background-color: #444; display: flex; position: absolute; top: 0; display: none; } .widget:hover > .menu { display: flex; } .widget:hover > .widget:hover + .menu { display: none; }
<div class="widget"> <div class="widget"> <div class="menu"><p>I should ONLY be visible when you hover the small inner widget</p></div> </div> <div class="menu"><p>I should ONLY be visible when you hover the big outer widget and NOT when you are hovering the small inner widget</p></div> </div>
The second approach was to make the .widget one of the first:
.wrap { position: relative; width: 500px; height: 500px; } .widget { position: absolute; background-color: #ddd; } .w1 { width: 500px; height: 500px; background-color: #eee; } .w2 { left: 200px; top: 200px; width: 150px; height: 150px; } .menu { background-color: #444; display: flex; position: absolute; top: 0; display: none; } .widget:hover > .menu { display: flex; } .widget:hover > .widget:hover + .menu { display: none; }
<div class="wrap"> <div class="widget w1"> <div class="menu"><p>I should ONLY be visible when you hover the big outer widget and NOT when you are hovering the small inner widget</p></div> </div> <div class="widget w2"> <div class="menu"><p>I should ONLY be visible when you hover the small inner widget</p></div> </div> </div>
On the side of the note, you should try not to use inline CSS.
source share