I'm trying fit a fluid image inside a resizable DIV
. The image must retain its proportions and never go beyond 100% (both width and height) - even if the containing DIV
is larger than the image.
The image must also be centered, both horizontally and vertically. Chrome and Safari does this perfectly - Internet Explorer 10 doesn't.
I've set up a quick jsfiddle to illustrate the issue.
HTML:
<div id="diver">
<img src="http://ie.microsoft.com/testdrive/Performance/Minesweeper/images/ie-logo.png" style="" />
</div>
And the css:
#diver {
border:1px solid #000000;
width:200px;
height:200px;
text-align:center;
display: table-cell;
vertical-align: middle;
}
img {
max-width:100%;
max-height:100%;
}
Try resizing the box to less than 100% width and height in Chrome and you will get something similar to these images:
Less than 100% height:
Less than 100% width:
Internet Explorer 10 however, only scales the height. The width will not go below 100%, which is the main issue.
I can get IE to scale the width, similar to Chrome/Safari, but it requires the DIV
height (yes, height) to be set to something low, like 10px, which is kindda weird imo.
I know it's possible to scale the image dynamically in javascript, but I don't see the need for extra javascript, when Internet Explorer should be able to handle the scaling correctly.