Search code examples
htmlcssbordercss-shapes

Border corner shape scoop doesn't work


I want to achieve the below shape using border-corner-shape property. But it doesn't work.

enter image description here

My code is available below:

.left-1 {
   background-color: #3498DB;
   border-corner-shape: scoop;
   border-radius: 30px;
   width: 200px;
   height: 200px;
}
<div class="left-1"></div>

Why does it not work?


Solution

  • Using Radial Gradients:

    Here is another alternative method to achieve the border corner scoop effect using radial gradients. In this method, we use multiple radial gradients and position them at the corners.

    .border-scoop {
      height: 300px;
      width: 300px;
      background: -webkit-radial-gradient(0% 100%, circle, transparent 15%, steelblue 15%) no-repeat, -webkit-radial-gradient(100% 0%, circle, transparent 15%, steelblue 15%) no-repeat, -webkit-radial-gradient(0% 0%, circle, transparent 15%, steelblue 15%) no-repeat, -webkit-radial-gradient(100% 100%, circle, transparent 15%, steelblue 15%) no-repeat;
      background: radial-gradient(circle at 0% 100%, transparent 15%, steelblue 15%) no-repeat, radial-gradient(circle at 100% 0%, transparent 15%, steelblue 15%) no-repeat, radial-gradient(circle at 0% 0%, transparent 15%, steelblue 15%) no-repeat, radial-gradient(circle at 100% 100%, transparent 15%, steelblue 15%) no-repeat;
      background-position: 0% 100%, 100% 0%, 0% 0%, 100% 100%;
      background-size: 75% 75%;
    }
    body {
      background: -webkit-linear-gradient(90deg, crimson, indianred, purple);
      background: linear-gradient(90deg, crimson, indianred, purple);
    }
    <div class="border-scoop"></div>


    Using Clip Path:

    Scooped border corner effect can also be achieved using clip-path. Pure CSS version supports only basic shapes (circle, polygon, ellipse etc) and does not support a path or combination of shapes but SVG (inline/external) can be used.

    .border-scoop {
      width: 200px;
      height: 200px;
      background-color: #3498DB;
      -webkit-clip-path: url(#scoop);
      clip-path: url(#scoop);
    }
    body {
      background: -webkit-linear-gradient(90deg, crimson, indianred, purple);
      background: linear-gradient(90deg, crimson, indianred, purple);
    }
    <svg width='0' height='0'>
      <defs>
        <clipPath id='scoop' clipPathUnits='objectBoundingBox'>
          <path d='M0.2,0 A0.2,0.2 0 0,1 0,0.2 
                         L0,0.8 A0.2,0.2 0 0,1 0.2,1
                         L0.8,1 A0.2,0.2 0 0,1 1,0.8
                         L1,0.2 A0.2,0.2 0 0,1 0.8,0z' />
        </clipPath>
      </defs>
    </svg>
    <div class='border-scoop'></div>


    Transparent scoop with Box Shadow:

    The below snippet is a variant of GCyrillus' answer which needs an extra element but would work even if the background of the page is not a solid color. This method however still has the same fixed and known size limitation that is mentioned in the other answer.

    It must be noted that box shadow has much better browser support than radial gradients.

    .border-scoop{
      height: 300px;
      width: 300px;
      position: relative;
      overflow: hidden;
    }
    .inner{
      position: absolute;
      top: 0px; left: 0px;
      height: 100%;
      width: 100%;
    }
    .border-scoop:before, .border-scoop:after, .inner:after, .inner:before{
      position: absolute;
      content: '';
      height: 30%; width: 30%;
      border-radius: 50%;
      background: transparent;
      box-shadow: 0px 0px 0px 210px steelblue;  
    }
    .border-scoop:before{
      top: -15%; left: 85%;
    }
    .border-scoop:after{
      top: -15%; left: -15%;
    }
    .inner:after{
      top: 85%; left: 85%;
    }
    .inner:before{
      top: 85%; left: -15%;
    }
    
    body{
      background: -webkit-linear-gradient(90deg, crimson, indianred, purple);
      background: linear-gradient(90deg, crimson, indianred, purple);
    }
    <div class="border-scoop">
      <div class="inner"></div>
    </div>