Код: Выделить всё
.container {
min-height: 500px;
min-width: 300px;
max-height: 500px;
max-width: 300px;
background: lightBlue;
//padding: 10px;
overflow: hidden;
}
.grid {
display: grid;
max-height: 100%;
grid-template-columns: repeat(1, minmax(1px, 1fr));
grid-template-rows: repeat(6, minmax(1px, 1fr));
// The above expands the images to match the width of the container, and then sets their
// height based on the original aspect ratio - most items are not visible (i.e., the images
// are expanding out of the grid container)
// if you swap the '6' and '1' above, the images will correctly shrink to fit in their container,
// at the largest aspect ratio that is supported
//padding: 10px;
background: green;
}
img {
max-height: 100%;
max-width: 100%;
object-fit: cover;
//padding: 5px;
background: red;
}< /code>
[img]https://cdn.pixabay.com/photo/2017/02/07/16/47/kingfisher-2046453_960_720.jpg[/img]
[img]https://cdn.pixabay.com/photo/2017/02/07/16/47/kingfisher-2046453_960_720.jpg[/img]
[img]https://cdn.pixabay.com/photo/2017/02/07/16/47/kingfisher-2046453_960_720.jpg[/img]
[img]https://cdn.pixabay.com/photo/2017/02/07/16/47/kingfisher-2046453_960_720.jpg[/img]
[img]https://cdn.pixabay.com/photo/2017/02/07/16/47/kingfisher-2046453_960_720.jpg[/img]
[img]https://cdn.pixabay.com/photo/2017/02/07/16/47/kingfisher-2046453_960_720.jpg[/img]
Подробнее здесь: https://stackoverflow.com/questions/795 ... mension-of