1.container {
2 position: relative;
3 width: 37%; /* The size you want */
4}
5.container:after {
6 content: "";
7 display: block;
8 padding-bottom: 100%; /* The padding depends on the width, not on the height, so with a padding-bottom of 100% you will get a square */
9}
10
11.container img {
12 position: absolute; /* Take your picture out of the flow */
13 top: 0;
14 bottom: 0;
15 left: 0;
16 right: 0; /* Make the picture taking the size of it's parent */
17 width: 100%; /* This if for the object-fit */
18 height: 100%; /* This if for the object-fit */
19 object-fit: cover; /* Equivalent of the background-size: cover; of a background-image */
20 object-position: center;
21}
22
23
24
25//Credit for the great answer of "Amaury Hanser", on stackoverflow:
26//https://stackoverflow.com/questions/51447317/image-height-same-as-width