Home > Enterprise >  Is there a way for SVG strokes to "skip" intersecting each other, the same sort of way tha
Is there a way for SVG strokes to "skip" intersecting each other, the same sort of way tha

Time:10-04

I could probably manually fake it using a solid-edged drop shadow filter around the strokes, set to the background color, but that's neither resilient nor ideal.

Visually, instead of this:

enter image description here

I want to have this (if the circle is on top):

enter image description here

CodePudding user response:

A posible solution would be creating a mask with a white rectangle and a black stroked <use> element that is using the circle.

Please note that the white rectangle is covering all the svg element and the stroke-width of the <use> element is wider than the stroke of the circle.

This way you create a hole in the rect that is letting you to see whatever you have in the background.

<svg fill="none" stroke="black" stroke-width="3">
  <mask id="m">
    <rect width="100%" height="100%" fill="white" />
    <use xlink:href="#c" stroke-width="10" />
  </mask>

  <rect x="10" y="5" width="70" height="70" mask="url(#m)" />

  <circle id="c" cx="80" cy="75" r="40" />

</svg>

  • Related