How to create a corset like effect with CSS?

前端 未结 2 1429
有刺的猬
有刺的猬 2021-01-29 00:19

I want to create a effect as below with CSS, initially, I was thinking to merge two rectangle with rounded corner, but I can\'t use that way since it is a sharp angle, not round

2条回答
  •  悲&欢浪女
    2021-01-29 01:16

    In my opinion you would either have to work with borders (as you did) or SVGs. For the shadow it does not work with borders and regular css-shadows, so you want to apply drop-shadow as a filter (or you can use a SVG for the shadow).

    This is what I came up with

    .triangle_left {
      width: 600px;
      height: 600px;
      position: relative;
      margin: 20px auto;
      border: 2px solid #cccccc;
      /* box-shadow: 0px 0px 8px 1px darkgrey; */
      border-radius: 20px;
    }
    
    .triangle_left:before {
      content: '';
      width: 0;
      height: 0;
      border-top: 30px solid transparent;
      border-left: 30px solid white;
      border-bottom: 30px solid transparent;
      filter: drop-shadow(4px 0px 0px #ccc);
      position: absolute;
      left: -6px;
      top: 50%;
    }
    
    .triangle_left:after {
      content: '';
      width: 0;
      height: 0;
      border-top: 30px solid transparent;
      border-right: 30px solid white;
      border-bottom: 30px solid transparent;
      filter: drop-shadow(-4px 0px 0px #ccc);
      position: absolute;
      right: -6px;
      top: 50%;
    }

提交回复
热议问题