Cut Corners using CSS

后端 未结 15 1160
悲&欢浪女
悲&欢浪女 2020-11-22 03:34

I\'m looking to \"cut\" the top left corner of a div, like if you had folded the corner of a page down.

I\'d like to do it in pure CSS, are there any methods?

15条回答
  •  礼貌的吻别
    2020-11-22 04:01

    CSS Clip-Path

    Using a clip-path is a new, up and coming alternative. Its starting to get supported more and more and is now becoming well documented. Since it uses SVG to create the shape, it is responsive straight out of the box.

    • CanIUse
    • Clip Path Generator

    div {
      width: 200px;
      min-height: 200px;
      -webkit-clip-path: polygon(0 0, 0 100%, 100% 100%, 100% 25%, 75% 0);
      clip-path: polygon(0 0, 0 100%, 100% 100%, 100% 25%, 75% 0);
      background: lightblue;
    }

    Some Text

    CSS Transform

    I have an alternative to web-tiki's transform answer.

    body {
      background: lightgreen;
    }
    div {
      width: 200px;
      height: 200px;
      background: transparent;
      position: relative;
      overflow: hidden;
    }
    div.bg {
      width: 200%;
      height: 200%;
      background: lightblue;
      position: absolute;
      top: 0;
      left: -75%;
      transform-origin: 50% 50%;
      transform: rotate(45deg);
      z-index: -1;
    }

    Some Text

提交回复
热议问题