Here is a work around for inner bordered rect
using symbol
and use
.
Example: https://jsbin.com/yopemiwame/edit?html,output
SVG:
<svg>
<symbol id="inner-border-rect">
<rect class="inner-border" width="100%" height="100%" style="fill:rgb(0,255,255);stroke-width:10;stroke:rgb(0,0,0)">
</symbol>
...
<use xlink:href="#inner-border-rect" x="?" y="?" width="?" height="?">
</svg>
Note: Make sure to replace the ?
in use
with real values.
Background: The reason why this works is because symbol establishes a new viewport by replacing symbol
with svg
and creating an element in the shadow DOM. This svg
of the shadow DOM is then linked into your current SVG
element. Note that svg
s can be nested and every svg
creates a new viewport, which clips everything that overlaps, including the overlapping border. For a much more detailed overview of whats going on read this fantastic article by Sara Soueidan.