Fitting an image to a size (HTML)
I want to fit an image into a bounded area on an HTML document, preferably without any scripting or over-elaborate methods. For instance, if I make a DIV with height:100;width:150;overflow:hidden and then place an image with height:100 inside, then a landscape (2:3) image will display fully and a portrait (3:2) image will be clipped to 67x100 within the DIV.
I am prescaling all my images to fit within the available space, i.e. either the width or height is equal to the frame and the other is equal or smaller.
How can I make the image fit in the space, centred and retaining its original aspect ratio?
There are many incredibly elaborate (and seriously ugly) solutions on the net, and I want something pure and simple.
LordoftheMonkeys
Veteran
Joined: 15 Aug 2009
Age:26
Posts: 927
Location: A deep,dark hole in the ground
I think you can use float: center for the image and vertical-align: center for the div. I usually post this questions on a programming forum like CodeCall.
_________________
I don't want a good life. I want an interesting one.
Thanks, vertical-align on the div is exactly the answer. I had 90% of the solution and was too tired of it to see the last step.
The answers on programming forums were terrible - how to rewrite the whole problem in dynamic HTML, PHP, VBScript, Javascript etc, etc, with the most gruesome mangling of the problem. What I have now is so simple and works perfectly (it is a cross-linked photo collection, with a scrollable thumbnail listing)
| Similar Topics | |
|---|---|
| Testing to see If I'm good enough with HTML to show my image |
06 Sep 2009, 11:59 pm |
| How do I get an image the right size for an Avatar? |
02 Aug 2010, 2:22 am |
| Not fitting in with NTs, not fitting in with Aspies? |
14 Apr 2007, 2:45 pm |
| fitting in |
12 Nov 2011, 2:05 pm |
