[edit : preamble]
Regardless of the nature of your response, please support your arguments with technical references from credible sources. Appreciate your help in advance.
[Question]
I am seeking to design a CSS grid layout that is responsive for images with varying numbers of elements while maintaining their original resolution and centering them in their cells. The largest image serves as the reference point, fitting exactly into its cell, and the grid adjusts responsively based on available space (creating new rows only when required).
While my current grid setup is satisfactory, it necessitates knowing the precise size of the largest square image to use it as the standard reference without any surrounding spaces.
It might be challenging to achieve this using pure CSS alone. I have been struggling with it and would appreciate any suggestions you can offer.
.gallery {
display: grid;
grid-gap: 1rem;
grid-template-columns: repeat(auto-fill, minmax(auto, 100px));
justify-items: center;
align-items: center;
}
.gallery img {
width: auto;
height: auto;
object-fit: scale-down;
object-position: center center;
}
<div class="gallery">
<img src="https://picsum.photos/25">
<img src="https://picsum.photos/50">
<img src="https://picsum.photos/75">
<img src="https://picsum.photos/100">
<img src="https://picsum.photos/25">
<img src="https://picsum.photos/50">
<img src="https://picsum.photos/75">
<img src="https://picsum.photos/100">
<img src="https://picsum.photos/25">
<img src="https://picsum.photos/50">
<img src="https://picsum.photos/75">
<img src="https://picsum.photos/100">
<img src="https://picsum.photos/25">
<img src="https://picsum.photos/50">
<img src="https://picsum.photos/75">
<img src="https://picsum.photos/100">
</div>
Having a flexible solution without relying on a hardcoded value like 100px would be highly beneficial.