I've been struggling to incorporate a hover effect into my responsive image grid. I want the image to have a dark overlay and fade in some text when hovered over, but I can't seem to make it work.
Take a look at my HTML structure:
<div class="tile">
<img src="some_image" class="animate">
<div class="overlay">
<p>Mahatma Gandhi</p>
</div>
Here's the CSS code I'm using:
.gallery .row .tile:hover ~ .tile img {
transform: scale(1.2);
}
Despite implementing this CSS rule, the desired result is not achieved upon hovering over the image.
What could be causing the issue?
UPDATE: After some tweaking, I managed to get the hover effect working and successfully added fading text.
Check out the updated code:
<div class="tile">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/d6/Tagore_Gandhi.jpg/220px-Tagore_Gandhi.jpg" class="animate">
<div class="overlay">
<div class="text">Mahatma Gandhi</div>
</div>
</div>
CSS Modifications:
.tile {
position: relative;
width: 100%;
}
.image {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: rgba(0, 0, 0, 0.8);
}
.tile:hover .overlay {
opacity: 1;
}
While the updated effect works, I believe it lacks a certain "feel." To enhance it, I aim to add a scaling effect to the image. Any suggestions on how I can achieve this?