CSS Display an Image Resized and Cropped

前端 未结 19 1581
时光取名叫无心
时光取名叫无心 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    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:

提交回复
热议问题