CSS Display an Image Resized and Cropped

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

    Live Example: https://jsfiddle.net/de4Lt57z/

    HTML:

    ...

    CSS:

        .crop img{
          width:400px;
          height:300px;
          position: absolute;
          clip: rect(0px,200px, 150px, 0px);
          }
    

    Explanation: Here image is resized by width and height value of the image. And crop is done by clip property.

    For details about clip property follow: http://tympanus.net/codrops/2013/01/16/understanding-the-css-clip-property/

提交回复
热议问题