paint-brush
How to De-Squeeze an Image Using CSSby@niiazaly-dhumaliev
2,472 reads
2,472 reads

How to De-Squeeze an Image Using CSS

by Niiazaly DzhumalievApril 14th, 2020
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

CSS has a convenient property called object-fit with cover value. It will crop the sides of an image and maintain its aspect ratio. It is eye-catching at first glance and disrupts the UI of your project. With this property, images in your project will look well sized and look well-sized. To fix the squeezing, CSS has an easy way to do it: apply "object-fit: cover" to the cover value. It is a convenient way to get rid of the squeezing.
featured image - How to De-Squeeze an Image Using CSS
Niiazaly Dzhumaliev HackerNoon profile picture

All images have different sizes. But most of the time we want to place an image and define dimensions by ourselves. By default, the whole image squeezed according to the given width and height. For instance, if you want to place an image with a width of 400px and a height of 500px the image will look like this:

The discrepancy between the original and the defined image sizes leads us to the issue. It is eye-catching at first glance and disrupts the UI.

To fix the squeezing, CSS has a convenient property called object-fit with cover value. What does it do?

When we apply

"object-fit: cover"
it will crop the sides of an image and maintain its aspect ratio. Now we have de-squeezed image alongside with squeezed one.

Conclusion:

With

object-fit cover
images in your project will look
well sized.