Search code examples
htmlcsscss-shapes

How to create a div with pointy edges?


can you help me to make like this div:

My Code:

body{
        display: flex;
        justify-content: center;
      }
      #talkbubble {
      width: 160px;
      height: 80px;
      background: #bc0a14;
      position: relative;
      -moz-border-radius: 10px;
      -webkit-border-radius: 10px;
      border-radius: 10px;
    }
    #talkbubble:before {
      content: "";
      position: absolute;
      right: 100%;
      top: 26px;
      width: 0;
      height: 0;
      border-top: 13px solid transparent;
      border-right: 26px solid #bc0a14;
      border-bottom: 13px solid transparent;
    }
    #talkbubble:after {
      content: "";
      position: absolute;
      left: 100%;
      top: 26px;
      width: 0;
      height: 0;
      border-top: 13px solid transparent;
      border-left: 26px solid #bc0a14;
      border-bottom: 13px solid transparent;
    }
<div id="talkbubble"></div>

I want to create this div with the same style in the image


Solution

  • here is an idea with pseudo element and radial-gradient. I used CSS variable to easily adjust the shape but it's not mandatory

    .box {
      width: 100px;
      height: 50px;
      margin:0 var(--w,20px);
      display:inline-block;
      border-radius: 15px;
      background: var(--c,red);
      position: relative;
    }
    
    .box:before,
    .box:after {
      content: "";
      position: absolute;
      top: 0;
      bottom: 0;
      width: var(--w,20px);
      right:calc(100% - 2px);
      background:
       radial-gradient(107% 100% at top    left,transparent 96%,var(--c,red) 100%) top, 
       radial-gradient(107% 100% at bottom left,transparent 96%,var(--c,red) 100%) bottom;
      background-size:100% 50.1%;
      background-repeat:no-repeat;
    }
    .box:after {
      left:calc(100% - 2px);
      right:auto;
      transform:scaleX(-1);
    }
    <div class="box"></div>
    
    <div class="box" style="--c:blue;--w:30px;"></div>
    
    <div class="box" style="--c:purple;--w:10px;height:60px"></div>