Cutting image diagonally with CSS

前端 未结 5 1490
不思量自难忘°
不思量自难忘° 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 20:43

    This one is a little bit dirty but... Here is the idea :

    HTML:

    body {
      background: #eee;
    }
    figure {
      display: inline-block;
      overflow: hidden;
      padding-left: 20px;
      margin-left: -20px;
      padding-top: 50px;
      margin-top: -50px;
      padding-right: 20px;
      margin-right: -20px;
      height: 200px;
      transform: rotate(-10deg);
    }
    figure img {
      transform: rotate(10deg);
    }

    Note: Another method could be using a pseudo-element to mask the picture, but this will not produce a real "cut" where you should be able to see through.

提交回复
热议问题