0

I have two divs; let's call them div 1 and div 2 and the one on top of the other is set to visibility:hidden:

picture

Basically the info div is supposed to appear whenever you hover the other one. That part works fine, except when I hover my mouse onto the text box, and it starts appearing and disappearing glitch-illy and it's extremely hard on the eyes.

What I want to achieve is that if div 1's area is hovered, even though it's behind another element, the visibility of div 2 will remain visible.

I suspect the issue is that mouse doesn't hover div 1 anymore, so div 2 disappears, then div 1 is hovered again, and repeat a thousand times in a second.

.ning-img, .bo-img {
  position:absolute;
    width:50%;
    height:100%;
    overflow:hidden;
    background-position: center center;
    background-size:cover;
    clip-path: polygon(32% 0, 100% 0, 68% 100%, 0% 100%);

}

.ning-img {
  left:0%;
  background-color:green;
}

.bo-img {
  left:50%;
  background-color:blue;
}
.ning, .bo {
  position:absolute;
  top:70%;
  left:10%;
  width:70%;
  height:10%;
  visibility:hidden;
  z-index:2;
}

.ning {
  background-color:purple;
}

.bo {
  background-color:yellow;
}

.bo-img:hover ~ .bo {
    animation-name:anim;
    animation-duration: 0.2s;
        animation-fill-mode: forwards;

}


.ning-img:hover ~ .ning {
    animation-name:anim;
    animation-duration: 0.2s;
        animation-fill-mode: forwards;

}

@keyframes anim {
    100% {
        visibility: visible;
    }
}
<!DOCTYPE html>
<html>
<!-- this is in the body -->
<div class="images">
  <div class="ning-img"></div>
  <div class="bo-img"></div>
  
  <div class="ning">hello</div>
  <div class="bo">hello2</div>


</div>

</html>

3
  • Forgot to add, there are multiple divs behind div 2, so it displaying on its own hover is not an option!
    – poppy pelt
    Commented Apr 15, 2023 at 8:53
  • Consider providing some reproducible example code so that we can get a better understanding of your situation and thus be able to give you the most relevant advice.
    – Wongjn
    Commented Apr 15, 2023 at 8:57
  • Just did! I hope it helps
    – poppy pelt
    Commented Apr 15, 2023 at 9:09

1 Answer 1

1

You could disable pointer events on the foreground element? doing this will maintain the hover state on the background element

.ning-img, .bo-img {
  position:absolute;
    width:50%;
    height:100%;
    overflow:hidden;
    background-position: center center;
    background-size:cover;
    clip-path: polygon(32% 0, 100% 0, 68% 100%, 0% 100%);

}

.ning-img {
  left:0%;
  background-color:green;
}

.bo-img {
  left:50%;
  background-color:blue;
}
.ning, .bo {
  position:absolute;
  top:70%;
  left:10%;
  width:70%;
  height:10%;
  visibility:hidden;
  z-index:2;
}

.ning {
  background-color:purple;
  pointer-events:none;
}

.bo {
  background-color:yellow;
}

.bo-img:hover ~ .bo {
    animation-name:anim;
    animation-duration: 0.2s;
        animation-fill-mode: forwards;

}


.ning-img:hover ~ .ning {
    animation-name:anim;
    animation-duration: 0.2s;
        animation-fill-mode: forwards;

}

@keyframes anim {
    100% {
        visibility: visible;
    }
}
<!DOCTYPE html>
<html>
<!-- this is in the body -->
<div class="images">
  <div class="ning-img"></div>
  <div class="bo-img"></div>
  
  <div class="ning">hello</div>
  <div class="bo">hello2</div>


</div>

</html>

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.