I think the property you're looking for is object-fit
img {
width: 200px; /* You can set the dimensions to whatever you want */
height: 200px;
object-fit: cover;
}
The object-fit
property works similarly to how you would using background-size: cover
on a background image to make it fill the page without stretching. This way, you can define a width in a rule that all images will follow to ensure that they are the same size without distorting your picture.
Other values you can use with this property includes:
fill
- stretch the image.
contain
- preserve the aspect ratio of the image.
cover
- Fill the height and width of the box.
none
- Keep the original size.
scale-down
- compare the differences between none and contain to find the smallest object size.
object-fit | CSS-Tricks
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…