How to emulate background-size: cover on <img>?
How can I resize and reposition the image inside a box, in such way that it covers the entire box, similar to how background-size: cover works. <div class="box" style="width: 100px; height: 100px;"> <img src="pic.jpg" width="413" height="325"> </div> I know I have to add overflow:hidden to the box and the image needs position: absolute . But what's the formula that gets me the right new size for the image, and left + top positions? this may be easier jQuery $('.box').each(function() { //set size var th = $(this).height(),//box height tw = $(this).width(),//box width im = $(this).children('img'