How to combine SVG path like below image

Viewed 413

Actual SVG Convert to Expected SVG

My Code looks like below.

<!DOCTYPE html>
<html>
<body>

<svg height="210" width="400">
  <path d="M10 10 L110 10 L110 110 L10 110 Z"  fill="none" stroke-width="2" stroke="red"/>
  <path d="M110 10 L210 10 L210 110 L110 110 Z"  fill="none" stroke-width="2" stroke="red"/>
  <path d="M110 110 L210 110 L210 210 L110 210 Z"  fill="none" stroke-width="2" stroke="red"/>
  
  

  Sorry, your browser does not support inline SVG.
</svg>

</body>
</html>

I want to convert actual SVG to Expected SVG. I am used the path element for draw each rectangle, i want remove the intersect line while drawing the SVG rect. Can you please suggest any solution.

1 Answers

In this case easy solution would be to code it manually like this:

<svg height="220" width="400" viewBox="0 0 400 220"> 
  <path d="M10,10 L210,10 L210,210 L110,210 L110,110 L10,110  L10,10" stroke="green" fill="none" />
</svg>

However for more complicated shapes this won't do. A solution would be removing the stroke from your shapes, fill them with white or whatever color you want and applying a filter to outline the group of shapes:

<svg height="220" width="400" viewBox="0 0 400 220">
<filter id="outline">
<feMorphology in="SourceAlpha" result="expanded"
operator="dilate" radius="3"/>
<feFlood flood-color="red" result="indi" />
<feComposite in ="indi" in2="expanded" operator="in" />
<feComposite in="SourceGraphic"/>
</filter>
  <g fill="white" filter="url(#outline)">
  <path d="M10 10 L110 10 L110 110 L10 110 Z"   />
  <path d="M110 10 L210 10 L210 110 L110 110 Z" />
  <path d="M110 110 L210 110 L210 210 L110 210 Z"  />
</g>  
</svg>

I hope it helps.

Related