Jump to content

trying to fit image in viewport

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.



Link to post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...