How to resize to the img tag appropriate?

前端 未结 3 1623
野趣味
野趣味 2020-12-28 16:28

I want to show an image in small windows but i need to save on the ratio of the image(I still want that people can know what it is). For example lets say that the image is 1

3条回答
  •  醉酒成梦
    2020-12-28 17:23

    If you use javascript, you could simply get the height and width of the image and divide one by the other to get a ratio, then multiply the height and width of the div against that ratio, then set the img dimensions to those numbers.

    Obviously that's a very simplistic way to say it, but I'm also not sure if you want to do this with JS or use a strictly CSS solution.

提交回复
热议问题