I am struggling with creating a mouse hover function that allows me to hide and show two pictures in the same position. Essentially, I want one picture to stay in place while another picture appears on top of it when hovered over. Both pictures should be the same size.
Below is an example of the code I have been working on:
<style>
.preview-image {
background-size: 0 0;
width: 100vw;
}
.nopadding {
padding: 0!important;
}
.container:hover .preview-image {
opacity: 1;
background-repeat: no-repeat;
background-size: cover;
height: 100px;
}
.container:hover .txt-container {
opacity: 0;
}
.txt-container {
opacity: 1;
font-weight: bold;
color: black;
}
.btn {
background-color: #4CAF50;
color: white;
font-size: 16px;
padding: 16px 32px;
}
</style>
<ul class="nopadding">
<div class="container">
<li class="preview-image" style="background-image:url(https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTadW0C0MkeampnVW-_sT7bMOemD3roUI5x-w&usqp=CAU);">
<div class="txt-container">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQXV2n5aZGMr6SoY-thS3xR6bPchCnUu23SiA&usqp=CAU" />
</div>
</li>
</div>
</ul>
For instance, without hovering, only the first picture will be displayed on the page:
https://i.sstatic.net/QR2nK.png
When hovering over the first picture, the second picture should overlay the first one while maintaining the same size:
https://i.sstatic.net/3j67b.png
I would appreciate any guidance on how to achieve this effect. Thank you!