How to use clip-path property for border in css

前端 未结 3 1384
暖寄归人
暖寄归人 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

    As far as I know, it's not really possible to make a border around an element with a clip-path. This method uses inside and outside elements. Source: https://codepen.io/bennettfeely/pen/azJWWX/

    .outside {
      position: relative;
        width: 70vmin;
        height: 70vmin;
        background: red;
        -webkit-clip-path: polygon(50% 0%, 83% 12%, 100% 43%, 94% 78%, 68% 100%, 32% 100%, 6% 78%, 0% 43%, 17% 12%);
    clip-path: polygon(50% 0%, 83% 12%, 100% 43%, 94% 78%, 68% 100%, 32% 100%, 6% 78%, 0% 43%, 17% 12%);
    }
    
    .inside {
      position: absolute;
      top: 5px;
      left: 5px;
      right: 5px;
      bottom: 5px;
      background: red;
      -webkit-clip-path: polygon(50% 0%, 83% 12%, 100% 43%, 94% 78%, 68% 100%, 32% 100%, 6% 78%, 0% 43%, 17% 12%);
      clip-path: polygon(50% 0%, 83% 12%, 100% 43%, 94% 78%, 68% 100%, 32% 100%, 6% 78%, 0% 43%, 17% 12%);
    }
    
    .inside:hover {
      background: white;
      transition: all .2s;
    }
    
    .outside:hover {
      background: green;
      transition: all .2s;
    }
    
    /* Center the demo */
    html, body { height: 100%; }
    body {
        display: flex;
        justify-content: center;
        align-items: center;
      background: papayawhip;
    }

提交回复
热议问题