CSS shape with inset curve and transparent background

后端 未结 2 1408
广开言路
广开言路 2020-12-02 00:36

I need to create a CSS shape like this image..

\"enter

Please check this fiddl

2条回答
  •  执笔经年
    2020-12-02 01:03

    Variant #01:

    CSS3 linear-gradient() can draw this background as well:

    CSS:

    div {
      background: linear-gradient(45deg, transparent 50px, tomato 50px);
    }
    

    Output Image:

    body {
      background: linear-gradient(lightgreen, green);
      min-height: 100vh;
      margin: 0;
    }
    div {
      background: linear-gradient(45deg, transparent 50px, tomato 50px);
      height: 150px;
      margin: 20px;
      width: 400px;
    }

    Variant #02:

    We can use :before and :after pseudo elements and use css3 transformation to make this shape with round corners.

    body {
      background: linear-gradient(lightgreen, green);
      min-height: 100vh;
      margin: 0;
    }
    div {
      border-radius: 10px;
      position: relative;
      overflow: hidden;
      height: 150px;
      margin: 20px;
      width: 400px;
    }
    div:before {
      border-radius: 0 0 10px 10px;
      transform-origin: 100% 0;
      transform: skewY(45deg);
      background: tomato;
      position: absolute;
      width: 45px;
      z-index: -1;
      content: '';
      bottom: -5px;
      left: 0;
      top: 0;
    }
    div:after {
      border-radius: 0 10px 10px 10px;
      background: tomato;
      position: absolute;
      content: '';
      left: 35px;
      bottom: 0;
      right: 0;
      top: 0;
    }

提交回复
热议问题