How can I fill a div with an image while keeping it proportional?

前端 未结 15 1413
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 00:56

I found this thread — How do you stretch an image to fill a

while keeping the image's aspect-ratio? — that is not entirely the thing that I want.

I h

15条回答
  •  眼角桃花
    2020-11-28 01:24

    .image-wrapper{
        width: 100px;
        height: 100px;
        border: 1px solid #ffffd;
    }
    .image-wrapper img {
        object-fit: contain;
        min-width: 100%;
        min-height: 100%;
        width: auto;
        height: auto;
        max-width: 100%;
        max-height: 100%;
    }

提交回复
热议问题