Reputation: 21
I am trying to get an image with unknown height and width to fit inside of a div with 300px width and 300px height. I always need to see the entire image.
Example 1: Image that comes in with 300px height and 200px width, will result in 100% height and 66% width of it's parent div
Example 2: Image that comes in with 200px height and 300px width, will result in 66% height and 100% width of it's parent div
Upvotes: 0
Views: 200
Reputation: 359
I'm not sure if this but I think you can ask it with jQuery:
if($('incoming_pic').css('height') > '300px'){
//do something
}
Upvotes: 0
Reputation: 8660
If you set the image as the background-image of the div you can use the css style
background-size: contain;
Here's a jsfiddle! http://jsfiddle.net/04y4dm06/1/
Upvotes: 0