M
M
Miku Hatsune2015-11-17 13:05:06
css
Miku Hatsune, 2015-11-17 13:05:06

"Smart" image resizing with CSS?

I don’t know how to clearly formulate my question, so it’s useless to send to Google, I just don’t know what to ask him.
I will explain my thoughts. Look at the screenshot:
5c909a2e674241e79dc980ec48fabb81.png
I need the image to be 100% wide, but if I do that, it stretches and loses proportions - in a word, horror.
How to resize an image using CSS so that it does not lose proportions, but is simply cut off a little?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
mr_dev1l, 2015-11-17
@Hatsune-Miku

img {
 width:100%;
 object-fit:cover;
}

Y
Yuri Yanin, 2015-11-17
@VPank

Still there is a variant with JS. Determine the width of the container div with a query and force the drawing to take the given width as a basis while increasing the height proportionally. Well, accordingly, the div must be of a fixed size so that it does not start to stretch along the height of the picture

K
Ksenia Mikhailova, 2015-11-17
@arizona

If you know the dimensions of the div ahead of time, you can set the image as background-image and use background-size.

S
sashabeep, 2015-11-24
@sashabeep

.parent{display:table-cell; vertical-align:middle;text-align:center}
.parent img{max-height:100%;max-width:100%}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question