How to maintain aspect ratio using HTML IMG tag

前端 未结 10 1460
面向向阳花
面向向阳花 2020-12-23 02:42

I am using an img tag of HTML to show a photo in our application. I have set both its height and width attribute to 64. I need to show any image resolution (e.g. 256x256, 10

10条回答
  •  礼貌的吻别
    2020-12-23 03:03

    None of the methods listed scale the image to the largest possible size that fits in a box while retaining the desired aspect ratio.

    This cannot be done with the IMG tag (at least not without a bit of JavaScript), but it can be done as follows:

     

提交回复
热议问题