How to add a circle on the top right corner of a button above the background and behind the border?

前端 未结 2 1362
轻奢々
轻奢々 2021-01-14 15:57

I wanna achieve the following result by using CSS:

So basically I want the circle to be on top of the button background but behind its border, with the butt

2条回答
  •  轮回少年
    2021-01-14 16:53

    One idea is to integrate the missing borders inside the circle

    .container {
      margin-top: 30px;
    }
    
    button {
      font-size: 20px;
      border: 2px solid black;
      padding: 8px 20px;
      position: relative;
    }
    
    button:before {
      content: "";
      position: absolute;
      top: -1px;
      right: -1px;
      transform:translate(50%,-50%);
      width: 40px;
      height: 40px;
      border-radius: 50%;
      background: 
       linear-gradient(black,black) left  /50% 2px,
       linear-gradient(black,black) bottom/2px 50%,
       #4da6ff;
     background-repeat:no-repeat;
    }

    Or you can simply consider mix-blend-mode. You have to pay attention to the value used as it will depend on the combination of the colors. In this case, the suitable one is darken

    .container {
      margin-top: 30px;
    }
    
    button {
      font-size: 20px;
      border: 2px solid black;
      padding: 8px 20px;
      position: relative;
    }
    
    button:before {
      content: "";
      position: absolute;
      top: -1px;
      right: -1px;
      transform:translate(50%,-50%);
      width: 40px;
      height: 40px;
      border-radius: 50%;
      background: #4da6ff;
      mix-blend-mode:darken;
    }

    A third way more fancy with only backgrounds:

    button {
      font-size: 20px;
      border:0 solid transparent;
      border-top-width:24px;
      border-right-width:24px;
      padding: 8px 20px;
      background:
         linear-gradient(black,black) top   /100% 2px,
         linear-gradient(black,black) bottom/100% 2px,
         linear-gradient(black,black) left  /2px 100%,
         linear-gradient(black,black) right /2px 100%,
         radial-gradient(circle, #4da6ff 19px,transparent 20px) left bottom/200% 200% padding-box border-box,
         #e2e2e6 padding-box;
      background-repeat:no-repeat;
    }

    Another idea is to place the circle behind the element and cut the background:

    .container {
      margin-top: 30px;
      position:relative;
      z-index:0;
    }
    
    button {
      font-size: 20px;
      border: 2px solid black;
      padding: 8px 20px;
      position: relative;
      background:radial-gradient(circle at top right,transparent 19px,#e2e2e6 20px);
    }
    
    button:before {
      content: "";
      position: absolute;
      z-index:-1;
      top: -1px;
      right: -1px;
      transform:translate(50%,-50%);
      width: 40px;
      height: 40px;
      border-radius: 50%;
      background:#4da6ff;
    }

提交回复
热议问题