I'm struggling to find a way to position a title at the bottom of each image in my grid gallery, right in the center of the photo with a light-gray background. I want the text to be fully visible regardless of the image used. Currently, I can only put text below the images but not on them. Any help would be greatly appreciated! Here is the code I have so far:
body {
margin: 0
}
.container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 20px;
background: rgb(255, 255, 255);
padding: 15px;
}
.container img {
width: 80%;
display: block;
background-color: cornflowerblue;
border-radius: 12%;
}
.container img:hover {
transform: scale(1.04);
}
h2,
p {
font-family: Arial, Helvetica, sans-serif;
font-weight: lighter;
}
.overlay {
position: absolute;
bottom: 10px;
left: 19px;
font-size: 13px;
}
<div class="container">
<img src="placeholder-image.png" alt="photo">
<img src="placeholder-image.png" alt="photo">
<img src="placeholder-image.png" alt="photo">
<img src="placeholder-image.png" alt="photo">
<img src="placeholder-image.png" alt="photo">
<img src="placeholder-image.png" alt="photo">
<img src="placeholder-image.png" alt="photo">
<img src="placeholder-image.png" alt="photo">
<img src="placeholder-image.png" alt="photo">
<img src="placeholder-image.png" alt="photo">
</div>