skip to Main Content

I have this flex container which has three circles and I want the first one to have a bite effect on the right, the middle one normal and the last circle a bite on the left.
I tried putting another circle on top of another and just adding margin to it but it doesn’t work for the third circle. Any idea how I can do this?

.container {
  display: flex;
  flex-direction: row;
  gap: 20px;
  position: relative;
  width: 100%;
}

.box1 {
  width: 300px;
  height: 300px;
  background-color: blue;
  border-radius: 50%;
  z-index: 10;
}

.add-edge-right {
  margin-left: 250px;
  background-color: white;
}

.add-edge-left {
  margin-right: 250px;
  background-color: white;
}
<div class="container">
  <div class="box1">
    <div class="box1 add-edge-right"></div>
  </div>
  <div class="box1"></div>
  <div class="box1">
    <div class="box1 add-edge-left"></div>
  </div>
</div>

Screenshot:

2

Answers


  1. I would suggest another way than flex.
    old school one with relative, absolute position and border
    (don’t forget the box-sizing otherwise it’s not working)

    If you want to change the size, for exemple container from 600 to 900:

    • container width 900px
    • box1 width, height 300px
    • box1:nth-child(2), several changes:
      we’ll put border to 50px, so 50 each side -> width, height 400px
      top -50px (height of the border)
    *,
    *:before,
    *:after {
      box-sizing: border-box;
    }
    
    body {
      margin: 0;
      padding: 0;
    }
    
    .container {
      position: relative;
      width: 600px;
    }
    
    .box1 {
      position: absolute;
      width: 200px;
      height: 200px;
      background-color: blue;
      border-radius: 50%;
      z-index: 10;
    }
    
    .box1:first-child {
      left: 0;
    }
    
    .box1:nth-child(2) {
      width: 260px;
      height: 260px;
      top: -30px;
      left: 50%;
      transform: translateX(-50%);
      z-index: 11;
      border: 30px solid white;
    }
    
    .box1:last-child {
      right: 0;
    }
    <div class="container">
      <div class="box1"></div>
      <div class="box1"></div>
      <div class="box1"></div>
    </div>
    Login or Signup to reply.
  2. If you want the ‘bite’ to be transparent, for example so a background shows through, then you can use CSS mask.

    In this snippet the width of the elements has been set at a CSS variable so you can easily change it if required as is the amount you want the bite ‘offset’ – to make it bigger or smaller.

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="UTF-8" />
      <meta http-equiv="X-UA-Compatible" content="IE=edge" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <title>Document</title>
      <link rel="stylesheet" href="index.css" />
      <style>
        .container {
          --w: min(300px, 30vw);
          --r: calc(var(--w) / 2);
          --x: calc(var(--w) / 3);
          /* the amount to displace the mask */
          display: flex;
          flex-direction: row;
          gap: min(20px, calc((100vw - (3 * var(--w))) / 2));
          position: relative;
          width: 100%;
        }
        
        .box1 {
          aspect-ratio: 1 / 1;
          width: var(--w);
          background-color: blue;
          border-radius: 50%;
          z-index: 10;
        }
        
        .box1:nth-child(1) {
          -webkit-mask-image: radial-gradient(circle at calc(var(--w) + var(--x)), transparent var(--r), black var(--r));
          mask-image: radial-gradient(circle at calc(var(--w) + var(--x)), transparent var(--r), black var(--r));
        }
        
        .box1:nth-child(3) {
          -webkit-mask-image: radial-gradient(circle at calc(-1 * var(--x)), transparent var(--r), black var(--r));
          mask-image: radial-gradient(circle at calc(-1 * var(--x)), transparent var(--r), black var(--r));
        }
      </style>
    </head>
    
    <body>
      <div class="container">
        <div class="box1">
        </div>
        <div class="box1"></div>
        <div class="box1"></div>
      </div>
    </body>
    
    </html>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search