How to use clip-path property for border in css

前端 未结 3 1428
暖寄归人
暖寄归人 2021-01-21 12:11

I have clip-part to make "cut corner" effect.

I would like to change background to white and use green border. Problem is, when I change ba

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-21 12:37

    add some gradient to fill the missing spaces:

    .test {
      background: red;
      width: 100px;
      height: 100px;
      box-sizing:border-box;
      
      /* CORNERS */
        clip-path: polygon(10px 0%, calc(100% - 10px) 0%, 100% 10px, 100% calc(100% - 10px), calc(100% - 10px) 100%, 10px 100%, 0% calc(100% - 10px), 0% 10px);
    }
    
    .test:hover {
      --grad:transparent 49.5%,green 50%;
      background: 
        linear-gradient(to top right   ,var(--grad)) top    right,
        linear-gradient(to top left    ,var(--grad)) top    left,
        linear-gradient(to bottom right,var(--grad)) bottom right,
        linear-gradient(to bottom left ,var(--grad)) bottom left,
        white;
      background-size:13px 13px; /* 10px of the clip-path + 3px of border */
      background-repeat:no-repeat;
      background-origin:border-box;
      cursor: pointer;
      
      border: 3px solid green;
    }

提交回复
热议问题