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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…