CSS Display an Image Resized and Cropped

前端 未结 19 1577
时光取名叫无心
时光取名叫无心 2020-11-22 08:09

I want to show an image from an URL with a certain width and height even if it has a different size ratio. So I want to resize (maintaining the ratio) and then cut the imag

相关标签:
19条回答
  • 2020-11-22 09:11

    In the crop class, place the image size that you want to appear:

    .crop {
        width: 282px;
        height: 282px;
        overflow: hidden;
    }
    .crop span.img {
        background-position: center;
        background-size: cover;
        height: 282px;
        display: block;
    }
    

    The html will look like:

    <div class="crop">
        <span class="img" style="background-image:url('http://url.to.image/image.jpg');"></span>
    </div>
    
    0 讨论(0)
提交回复
热议问题