Clip path inset circle?

前端 未结 6 1291
北荒
北荒 2020-11-28 14:56

Is it possible to create an inset circle clip path so that the clip path would effectively cut a hole through the div in the center opposed to only showing the center?

6条回答
  •  星月不相逢
    2020-11-28 15:14

    I don't think you can achieve this with clip-path but you can certainly cut a hole in a div using the radial-gradient background images. This has much better browser support than clip-path too.

    Note: This approach (and box-shadow ) will work only when the element that is covering the content below has a colored fill. If instead of sandybrown color, there needs to be another image on top then these approaches will not work because they don't actually cut a hole, they just mimic that effect.

    .div-with-hole {
      height: 100vh;
      background: radial-gradient(circle at center, transparent 25%, sandybrown 25.5%);
      background-size: 100% 100%;
      background-position: 50% 50%;
      transition: all 2s ease;
    }
    .div-with-hole:hover {
      background-size: 400% 400%; /* should be 100% * (100 / transparent % of radial gradient */
    }
    body {
      background: url(http://lorempixel.com/800/800/nature/1);
      min-height: 100vh;
      margin: 0;
      padding: 0;
    }

提交回复
热议问题