CSS Display an Image Resized and Cropped

前端 未结 19 1863
时光取名叫无心
时光取名叫无心 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 08:53

    css template


    .crop {
        float: left;
        margin: .5em 10px .5em 0;
        overflow: hidden; /* this is important */
        position: relative; /* this is important too */
        border: 1px solid #ccc;
        width: 150px;
        height: 90px;
    }
    .crop img {
        position: absolute;
        top: -20px;
        left: -55px;
    }
    

提交回复
热议问题