I want to create a simple photo gallery. I want to scale every photo such that it has its maximum size in the window respecting its original ratio.
Currently, I have for every photo an <img>
with the following styles
html, body {
height: 100%;
}
img
{
display:block;
width:auto;
height:auto;
max-width:98%;
max-height:95%;
}
This nicely scales down images which are to big to fit into the viewport. However, if the image is smaller than the viewport, then it does not get stretched. Any idea how I could add this stretching without Javascript?
I can only think of a solution which requires me to know the image ratio (then I can set width and height using vh and vw values) in advance and I would like to avoid this. Also, I do not like to set it as a background image of a page spanning div with background-size: cover
. This would introduce stupid gaps between my images if I do not know the image ratio.
Any idea? :) I know that it is probably not possible....
Thank you!