The solution is to change the div
to a table. As a rule, you should not use tables for positioning, but when it comes to old non-standard browsers, sometimes this is the only choice. Demo here . For recording, this also works in Internet Explorer 6.
the code:
CSS
#theDiv { width: 200px; height: 200px; text-align: center; vertical-align: middle; } #theImg { max-width: 190px; max-height: 190px; }β
HTML
<table id="theDiv" style="border: solid 1px #000"> <tr> <td> <img id="theImg" src="http://cdn1.sbnation.com/community_logos/9156/gangreen-small.jpg" /> </td> </tr> </table>
Here's an update that uses CSS instead of changing the markup to the actual table:
#theDiv { display: table; width: 200px; height: 200px; text-align: center; vertical-align: middle; } #theImg { max-width: 190px; max-height: 190px; } .tr { display: table-row; } .td { display: table-cell; vertical-align: middle; } <div id="theDiv" style="border: solid 1px #000"> <div class="tr"> <div class="td"> <img id="theImg" src="http://lorempixel.com/100/100/" /> </div> </div> </div>
source share