Jump to content

trying to fit image in viewport


BlobZ

Recommended Posts

I'm trying to force an image to be displayed totally within a viewport maximizing either the width(landscape picture) or height(portrait picture) so that the picture is always fully displayed. Can anyone provide HTML/CSS to achieve this.  My pictures are larger than the viewport so always need shrinking.

Thanks

 

Link to comment
Share on other sites

This should work:

display: block;
max-width: 100vw;
max-height: 100vh;
width: auto;
height: auto;

The element containing the image should take up the full size of the window for this to work correctly.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...