I have a variety of images with different dimensions, ranging from 50x100 to 4000x4000 pixels.
My objective is to display these images in their original size or scale them down to fit within the browser window. However, I have encountered an issue where the images upscale if the browser window is larger than the image itself, despite using the background image property:
<div class="slide-pane" style="background-image: url(<insert image url here>);"></div>
.slide-pane {
background-repeat: no-repeat;
background-size:auto;
position: absolute;
background-position: center;
background-repeat: no-repeat;
height: 80%;
width: 80%;
}
I have come across JavaScript and jQuery solutions such as:
- https://github.com/gutierrezalex/photo-resize
- How to resize an image to fit in the browser window?
Despite these solutions, I am seeking a CSS-only approach to resolve this issue.