0

The image is stretched when I try to make the size smaller.

http://jsfiddle.net/QEpJH/878/

.container img {
    display: block;
    width: 100%;
    height: 60vh;
    /*object-fit: cover; // doesn't work in Internet Explorer */
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Light_Warrior
  • 183
  • 1
  • 4
  • 17
  • 2
    Possible duplicate of [CSS force image resize and keep aspect ratio](https://stackoverflow.com/questions/12991351/css-force-image-resize-and-keep-aspect-ratio) – Peter B Apr 24 '18 at 11:15

4 Answers4

4

You need to make it scalable by 1:1

so use
width: auto; instead of width:100;.

or use height: auto; and width: 100%; in case you want to cover the whole width.

But remember if you cover the whole width, the height will increase.

Sarvan Kumar
  • 926
  • 1
  • 11
  • 27
Rakowu
  • 154
  • 10
  • I need the image to have a full width, but the height to be smaller, like 60 of the view port. – Light_Warrior Apr 24 '18 at 11:16
  • 1
    Try using background-image and use background-size: contain or cover. Otherwise use a container wrapping your image with an height of 60vh and overflow hidden. But you should use a horizontal taken imageinstead of an vertical taken. It makes it easer for you :) Here is an other example. http://jsfiddle.net/Rakowu/QEpJH/880/ – Rakowu Apr 24 '18 at 11:17
  • *EDIT: Here is an other example. http://jsfiddle.net/Rakowu/QEpJH/881/ – Rakowu Apr 24 '18 at 11:25
2

If you set the width to auto, the image will adjust itself to the given height without any stretch.

.container img {
        display: block;
        width: auto;
        height: 60vh;
    }
Laurent Mouchart
  • 216
  • 1
  • 3
  • 13
0

Try ratio in only percentage or use similar ratio

.container img {
   display: block;
   width: 30%;
   height: 30%;
   /*object-fit: cover; // doesn't work in Internet Explorer */
}
Sarvan Kumar
  • 926
  • 1
  • 11
  • 27
ruchika jain
  • 160
  • 11
0

if you set the image as a background instead and use

background-size:cover

you will lose the stretching but some of the image may get cut off

to counter this slightly you can use

background-position

to position the image in a more desirable place

S Morris
  • 25
  • 3