1

I have an image I want as big as possible, but I want 100% of the image visible no matter how the window is resized. I also want to maintain image ratio.

I have tried doing

img{
   width: 100vh;
}

but that will cut off some of the image depending on the size of the window.

Here are some examples of what I want:

When the width is restrictive

When the height is restrictive

Joey Carlisle
  • 586
  • 4
  • 12

2 Answers2

0

You could try to set your image with screen size then use object-fit: cover to set image always fitting the container;

img{
   width: 100vw;
   height: 100vh;
   object-fit: contain;
}
Martin Choraine
  • 2,296
  • 3
  • 20
  • 37
0

Try the following, it will max out the width of the containing element and also use height auto to maintain the aspect ratio of the image(s)

img {
    width:100%;
    height:auto;
  }
DraganAscii
  • 322
  • 1
  • 9