How to use clip-path property for border in css

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

    i'll make an answer of my comment for readability :

    For infos , if clip-path is used on a 2 level container, it is possible to add a shadow around the translucide edges with drop-shadow() filter .

    • clip-path applied on the child
    • drop-shadow() on the parent
    • without a blur , it looks like a border no matter the shape : https://jsfiddle.net/q9tdpvfg/

    jsfiddle demo in the snippet below:

    .test div {
      background: red;
      width: 100px;
      height: 100px;
      /* 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 {
      filter: drop-shadow(0px 3px 0px green) drop-shadow(3px 0px 0px green) drop-shadow(-3px 0px 0px green) drop-shadow(0px -3px 0px green);
      /* made 1 for each sides */
    }
    
    .test:hover div {
      background: white;
      cursor: pointer;
    }
    
    .test {
      width: max-content;
    }
    
    .test div {
      /* demo purpose */
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
    }
    TEST

提交回复
热议问题