CSS Display an Image Resized and Cropped

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

    Try using the clip-path property:

    The clip-path property lets you clip an element to a basic shape or to an SVG source.

    Note: The clip-path property will replace the deprecated clip property.

    img {
      width: 150px;
      clip-path: inset(30px 35px);
    }

    More examples here.

提交回复
热议问题