My goal is to create a hover effect on an image where it becomes semi-transparent and displays text that is initially hidden using display: none
. Right now, when I hover over an image, it does become semitransparent (.single-image:hover
is working), but the text doesn't show up. When the text was visible (not set to display: none
), it appeared over the image in the bottom left corner. I assumed that since it's positioned over the image, the hover pseudo-class would trigger its visibility. I also attempted setting the z-index of .attribution
to 1, but that didn't have any effect.
<div className="image-container">
<a href={image.links.html} target="_blank" rel="noopener noreferrer">
<img className="single-image" src={image.urls.regular} alt="" />
<p className="attribution">Unsplash</p>
</a>
</div>
.image-container {
display: inline-block;
position: relative;
}
/* Text */
.attribution {
display: none;
color: white;
position: absolute;
bottom: 20px;
left: 20px;
}
.attribution:hover {
display: block;
}
.single-image {
margin: 7px;
height: 350px;
width: 350px;
object-fit: cover;
}
.single-image:hover {
opacity: 0.7;
transition: 0.5s;
}