Hide an image by hovering over the div

Asked

Viewed 515 times

-1

I’m trying to make an image disappear by hovering over the div but I have a problem: when I move the mouse the image disappears, but I can’t click the link from the back div. Code:

<div class="col-md-8"> 
<div class="elemento-um"> 
<!-- LightWidget WIDGET -->
</div></div>

<div class="ico">
<a href='#'><img src='icon.png' /></a>
</div>

CSS:

.elemento-um {
    background: rgba(0, 0, 0, 0);
     margin-top: -127px;
     height: 107px;
     overflow: hidden; 
} 

.ico {
     opacity: 1;
     top: -140px;
     transition: .5s ease;
     z-index: 111;
     position: absolute; 
}

.ico a{ 
display: none; 
visibility:visible; 
} 

.ico:hover a {  
visibility: block; 
}
  • 3

    Read only by your report it is impossible to give you an accurate answer. Please edit your question by placing the HTML and CSS code you have. And if possible take the site tour to better understand how it works here https://answall.com/tour

  • 1

    In addition to the @hugocsl comment, the [Ask] page goes straight to the point. It is always recommended to include a [mcve].

  • 2

    @hugocsl, sorry, didn’t know. I edited the question with the code.

1 answer

0


Lia,

The code seems to be contrary to what you asked, so I’ll answer based on your question.

The estate visibility:block does not exist, the correct would be visility:visible. The block is from the display. display:block.

The display:none hides the screen element, already the visibility:hidden leaves the element there only that hides the content.

But in that case it wouldn’t do display:none in the Hover because when you see the element will hide it and as it hid it will no longer be in Hover then the element will appear again and be "flashing" on the screen appearing and disappearing.

the ideal would be to put a opacity:0 in the image when you see it in the div.ico.

Ex:

.elemento-um {
    background: rgba(0, 0, 0, 0);
     margin-top: -127px;
     height: 107px;
     overflow: hidden; 
} 

.ico {
     opacity: 1;
     top: -140px;
     transition: .5s ease;
     z-index: 111;
     position: absolute; 
}

.ico:hover a {  
   visibility:hidden
}

Follow an example fiddle:

https://jsfiddle.net/ey0m7rta/9/

  • Thank you so much for taking the time to help me! That’s exactly what it was. Sorry too for the mistake, I got confused when it came to publishing. Have a great night!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.