How to create a triangular shape with curved border?

前端 未结 2 1305
不知归路
不知归路 2020-12-06 23:19

I want to do this shape using CSS not as an image can I but I get the green shape and I can\'t get the all background transparent !

#arrowbox:before {
             


        
2条回答
  •  旧时难觅i
    2020-12-07 00:12

    You can do it with some perspective and rotation:

    .box {
      margin:20px;
      padding:20px calc(50% - 100px); /* this will fix the max width to 2x100px */
      /* the horizontal lines (one on each side)*/
      background:
        linear-gradient(red,red) left,
        linear-gradient(red,red) right;
      background-size:calc(50% - 100px) 2px;
      background-repeat:no-repeat;
      /* */
      text-align:center;
      position:relative;
    }
    .box::before,
    .box::after{
      content:"";
      position:absolute;
      top:-10px; /* lower than 0 to avoid the overlap due to rotation */
      /* same as the padding */
      left:calc(50% - 100px); 
      right:calc(50% - 100px);
      /* */
      bottom:50%;
      border:3px solid red;
      border-bottom:none;
      border-radius:15px 15px 0 0;
      /* adjust here to control the shape  */
      transform:var(--s,scaley(1)) perspective(40px) rotateX(25deg);
      /* */
      transform-origin:bottom;
    }
    .box::after {
      --s:scaley(-1);
    }
    some text here
    more and more
    text here
    even more
    and more
    text here

    Another idea with skew transformation:

    .box {
      margin:20px;
      padding:20px calc(50% - 100px); /* this will fix the max width to 2x100px */
      /* the horizontal lines (one on each side)*/
      background:
        linear-gradient(red,red) left,
        linear-gradient(red,red) right;
      background-size:calc(50% - 100px) 2px;
      background-repeat:no-repeat;
      /* */
      text-align:center;
      position:relative;
    }
    .box::before,
    .box::after,
    .box span::before,
    .box span::after{
      content:"";
      position:absolute;
      top:0;
      left:calc(50% - 100px); 
      right:50%;
      bottom:50%;
      border:2px solid red;
      border-bottom:none;
      border-right:none;
      border-radius:10px 0 0 0;
      transform:var(--s,scaleX(1)) skew(-35deg);
      transform-origin:right bottom;
    }
    .box::after {
      --s:scalex(-1);
    }
    .box span::before {
      --s:scaleY(-1);
    }
    .box span::after {
      --s:scale(-1);
    }
    some text here
    more and more
    text here
    even more
    and more
    text here

提交回复
热议问题