I have this grid where (usually) you can select one of the tiles. A selected tile is supposed to have a transparent blue overlay. How can you make an image overlay in a grid that remains the width of its container when resizing the grid width?
As such:
I made .tile__overlay position: absolute;
, which looks good at first glance. But it means that I lose the responsiveness, meaning that the overlay does not adjust to its parent size when the tiles are smaller than their maximum size.
.grid {
display: grid;
grid-gap: 6px;
max-width: 306px;
grid-template-columns: minmax(min-content, 150px) minmax(min-content, 150px);
}
.tile {
padding: 0;
border: 0;
max-height: 150px;
max-width: 150px;
}
.tile__image {
height: 100%;
width: 100%;
max-height: 150px;
max-width: 150px;
display: block;
object-fit: contain;
}
.tile__overlay {
width: 100%;
height: 100%;
background-color: rgba(29, 151, 255, 0.9);
}
<div class="grid">
<button class="tile" type="button">
<img src="https://i.picsum.photos/id/1/150/150.jpg" alt="">
</button>
<button class="tile" type="button">
<img src="https://i.picsum.photos/id/18/150/150.jpg" alt="">
</button>
<button class="tile" type="button">
<img src="https://i.picsum.photos/id/33/150/150.jpg" alt="">
<div class="tile__overlay" />
</button>
<button class="tile" type="button">
<img src="https://i.picsum.photos/id/47/150/150.jpg" alt="">
</button>
</div>