How to resize to the img tag appropriate?

前端 未结 3 1620
野趣味
野趣味 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条回答
  •  Happy的楠姐
    2020-12-28 17:08

    If your parent div has a set width and height, you could set the max-width and max-height of the img to 100%:

    div {
      width: 100px;
      height: 100px;
    }
    div > img {
      max-width: 100%;
      max-height: 100%;
    }
    

    (It's always a good practice to give images max-width of 100%, for mobile browsers etc.)

提交回复
热议问题