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? 回答1: this may be easier jQuery $('.box').each(function() { /