Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to make a div overlap another while hovered

I wanted to make a div that contains some info about a product and when the user hovered the product that div that contains information pops up but the info div seems to be glitching somehow and isn’t stable

Here’s the code:

.product {
  position: absolute;
  background-color: blue;
  width: 100px;
  height: 200px;
  z-index: 1;
}
.info {
  position: absolute;
  background-color: red;
  width: 300px;
  height: 300px;
  z-index: 2;
  opacity: 0.5;
  visibility: hidden;
}
.product:hover + .info {
  visibility: visible;
}
<div class="parent">
  <div class="product"></div>
  <div class="info"></div>
</div>

How can I have a stable version that doesn’t glitch and appear and disappear every millisecond

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It happens because your mouse is hovering .info instead of .product. You need to add .info:hover

.product {
  position: absolute;
  background-color: blue;
  width: 100px;
  height: 200px;
  z-index: 1;
}
.info {
  position: absolute;
  background-color: red;
  width: 300px;
  height: 300px;
  z-index: 2;
  opacity: 0.5;
  visibility: hidden;
}
.product:hover + .info, .info:hover {
  visibility: visible;
}
<div class="parent">
  <div class="product"></div>
  <div class="info"></div>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading