Ever wanted an image to fit exactly into a certain given dimension, but while keeping its aspect ratio and avoid having a squished image? This wasn’t something that could easily be done using CSS for the longest time. One trick was to resort to using a background image instead to go around the issue. Well the problem is no more with the object-fit property!
Along with inherit, initial and unset, there are 5 more possible values for object-fit:
... read the whole story at alligator.io.
- contain: The image keeps its original aspect ratio, but resized so that the longest of either the height or width can fit in the given dimensions.
- cover: The image keeps its original aspect ratio and the image area is completely covered.