How to create a corset like effect with CSS?

前端 未结 2 1427
有刺的猬
有刺的猬 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:12

    An idea is to build the shape using gradient and rely on drop-shadow filter

    .box {
      margin-top:50px;
      border-radius:10px;
      width:200px;
      height:200px;
      background:
      /*the middle line */
        repeating-linear-gradient(to right,gold 0px,gold 5px,transparent 5px,transparent 10px) center/calc(100% - 40px) 2px,
        /*The background*/
        linear-gradient(to bottom right,#fff 49%,transparent 50%) 100% calc(50% - 10px) / 20px 20px,
        linear-gradient(to top    right,#fff 49%,transparent 50%) 100% calc(50% + 10px) / 20px 20px,
        linear-gradient(to bottom left ,#fff 49%,transparent 50%) 0    calc(50% - 10px) / 20px 20px,
        linear-gradient(to top    left ,#fff 49%,transparent 50%) 0    calc(50% + 10px) / 20px 20px,
        
        linear-gradient(#fff,#fff) top    right / 20px calc(50% - 20px),
        linear-gradient(#fff,#fff) bottom right / 20px calc(50% - 20px),
        
        linear-gradient(#fff,#fff) top    left / 20px calc(50% - 20px),
        linear-gradient(#fff,#fff) bottom left / 20px calc(50% - 20px),
        
        linear-gradient(#fff,#fff) center/calc(100% - 40px) 100%;
       background-repeat:no-repeat;
       filter:drop-shadow(0 0 5px #000); 
    }
    
    body {
      background:pink;
    }
    <div class="box">
    </div>

    You can also do it with clip-path but you need an extra wrapper where you apply the drop-shadow filter

    .box {
      margin-top: 50px;
      border-radius: 10px;
      width: 200px;
      height: 200px;
      background: 
       repeating-linear-gradient(to right, gold 0px, gold 5px, transparent 5px, transparent 10px) center/100% 2px no-repeat,
       #fff;
      clip-path:polygon(
      0 0,100% 0,
      100% calc(50% - 20px),calc(100% - 20px) 50%,100% calc(50% + 20px),
      100% 100%, 0 100%,
      0 calc(50% + 20px),20px 50%,0 calc(50% - 20px)
      );
    }
    
    .drop {
      filter: drop-shadow(0 0 5px #000);
    }
    
    body {
      background: pink;
    }
    <div class="drop">
      <div class="box">
      </div>
    </div>

    0 讨论(0)
  • 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%;
    }
    <div class="triangle_left">
    
    </div>

    0 讨论(0)
提交回复
热议问题