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

前端 未结 2 1340
轻奢々
轻奢々 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:54

    Use a pseudo element (::after) to draw the border above the circle:

    .container {
      margin-top: 30px;
    }
    
    button {
      position: relative;
      font-size: 20px;
      border: none;
      padding: 8px 20px;
    }
    
    button::before {
      position: absolute;
      top: -20px;
      right: -20px;
      width: 40px;
      height: 40px;
      border-radius: 25px;
      background: #4da6ff;
      content: '';
    }
    
    button::after {
      position: absolute;
      top: -2px;
      right: -2px;
      bottom: -2px;
      left: -2px;
      border: 2px solid black;
      content: '';
    }

提交回复
热议问题