How to set an image's width and height without stretching it?

前端 未结 12 1591
南旧
南旧 2020-11-28 05:22

If I have:

#logo {
    width: 400px;
    height: 200px;
}

then


12条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 05:28

    2017 answer

    CSS object fit works in all current browsers. It allows the img element to be larger without stretching the image.

    You can add object-fit: cover; to your CSS.

提交回复
热议问题