Cutting image diagonally with CSS

前端 未结 5 1483
不思量自难忘°
不思量自难忘° 2020-12-15 20:40

How to cut away part of an image or container diagonally using CSS?

The part that needs to be cut away has the form of a triangle

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-15 21:08

    You could use a pseudo element, combined with overflow:hidden;

    Result

    enter image description here

    div {
      height: 300px;
      width: 300px;
      position: relative;
      overflow: hidden;
      background: url(http://placekitten.com/g/300/300);
    }
    div:after {
      content: "";
      position: absolute;
      top: 93%;
      left: 0;
      height: 100%;
      width: 150%;
      background: red;
      -webkit-transform: rotate(-5deg);
      -moz-transform: rotate(-5deg);
      transform: rotate(-5deg);
    }

提交回复
热议问题