Skip to content

Image Distortion

About 364 wordsAbout 1 min

2023-08-03

Image Distortion

When we cannot control the aspect ratio of the images in the web page, it is best to consider in advance and provide solutions when the image aspect ratio is inconsistent.

In the example below, we have a card component with a photo. It looks good.

Delicious food

A delicious meal

At that time, if the aspect ratio of the image used was inconsistent, the image would be stretched:

Delicious food

A delicious meal

The simplest solution is to use CSS object-fit.

.card__image {
  object-fit: cover;
}

Example

object-fit: cover

Adjust the container size to see the effect