I’m creating a redesign of a website. The site will have slideshows which will display in a modal window. The photos are not all the same size. I’ve got the modal window resizing to 85% of the height and width of the view port.
I’ve got the photos displaying in the modal window. Where I’m running into trouble is getting the pictures to retain the correct aspect ratio and not resize bigger than the photo size.
Currently, if an image is smaller in width or height of the modal window, the image displays properly. If the image is larger, it fills the modal window not retaining the aspect ratio.
I tried Googling this and found many different CSS tricks. None do exactly what I want
Here is the CSS and HTML I’m using for my modal window (BTW, this is the code created from a PHP script):
It needs testing with different sized images to see if its working properly. It should maintain aspect ratio but of course won’t fill the whole modal as you would need to enlarge and crop to do that.
It would be helpful if you could put up a working demo on codepen (or similar )with your images in place so we can see better what’s happening.
Did you read Paul’s request for a working demo on CodePen?
AND, would you include a URL to the images?
FYI, I noticed that the image names have a space in them. While they may work at this time, image names with spaces can “break” (which is probably the reason for the space? ). For the record, it is very strongly recommended that image names, just like URLs, not have spaces in them.
I’ve cobbled together most of your code here (apart from the js) so that we can talk about what needs doing. I’ve made the modal fit the image instead of being oversized.
This is only the first draft and needs testing with different sized images of course but I’m finished for the day now
Would it not be better to use a tried and tested script that is known to be responsive, works with images of different sizes in the same slideshow, and give no problems?
I’ve used Venobox on a few sites with no problems.
Yes generally there’s no need to re-invent the wheel and there are plenty of good slideshows around.
I suppose it all depends on what features you want or if you want something very simple then coding your own could be worth it (as long as you know what you are doing).
Since you want a demo, I’m going to give you one: edit: see post #10
Look at the 2014 photos. When you scroll through them you will notice that the popup window resizes with the photo. I’ve tried setting a height on the CSS style popup, but that causes the photo to get cut off even though the window is now longer and has more area for the photo.
I managed to get it to work on the PC, but on a tablet and cell, the bottom of the image and the image number are missing. It seems that at a smaller screen size the content area for the photo is not resizing properly. It should extend to the bottom of the window. Additionally, I’d like the image number to remain at the bottom of the window.
The div in question is div.content which I set the height of to 100%.
Edit: I found a max-height of 30% that was causing the div to cut off the lower part of the photo. now how to get the image number to stay in a fixed position at the bottom of the window.
I want the image number at the bottom of the window in a fixed position regardless of the image size.
Do I need to use some JavaScript to read the height of the image and div.content and calculate the offset, forcing the image number to be in a fixed position?
Thanks a ton Ray.H. That solved the position problem.
I just noticed that despite thinking I was done with this pop up window. On my cellphone in landscape, the window extends down below the end of the window.
Hi,
Pauls’ demo from post #5 seems to resolve that problem.
View it on codepen then click “export” on the bottom right corner to download the zip file.
Run those files from your local machine for further testing.
You will see that he has a max-height on the images that is scaling them to the viewport height.
I don’t think there will be a magic bullet that will fix your current modal window as it has fixed heights and overflow:hidden on the .popup.
Your images are not scaling correctly in that set-up since they are only height:auto;
Combined with a wide screen in landscape mode, your image width is still controlling the image height.