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 implement the hover effect on an image to be displayed another image over?

This is the html code

<img class="footballinfo" src="FootBallInfo.jpg" alt="FootBallInfo1" width="600" height="400" >
<img class="readmore" src="ReadMore.jpg" alt="readmore1" width="600" height="400" >

This is the CSS code

.footballinfo{
    position: absolute;
    top:230px;
    left: 400px;
}
.readmore{
    position: absolute;
    top:230px;
    left: 400px;
    display: none;
}
.footballinfo:hover .readmore{
    display: inline;
    opacity:0.6;
}

This is the code that I have came up with to do the hover effect. But for some reason it doesn’t give the expected output of displaying the other image. Could you spot out the mistake that I have done in one of these lines of code ?

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 :

You can not target the element from the neighbour element like your code. These images need to be in the same container, like this:

<div class="container">
  <img class="footballinfo" src="FootBallInfo.jpg" alt="FootBallInfo1" width="600" height="400" >
  <img class="readmore" src="ReadMore.jpg" alt="readmore1" width="600" height="400" >
 </div>

And then you can select the readmore element and style it as you want with this kind of code in css:

.container:hover .readmore {
  // your styles go here
}
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