Trying to understand how the viewBox attribute works in SVG, but the code below is confusing me. Can someone please explain if this is a bug or the expected behavior of SVG? I can't seem to figure out what I'm doing wrong...
<svg class="symbol"><symbol id="Atom" preserveAspectRatio="xMinYMin meet" viewBox="0 0 10 7"><path d="M3 6 4 7 6 7 4 4 5 3 8 7 10 7 5 0 0 7 2 7Z"></path></symbol></svg>
This is my SVG symbol here, and I'm attempting to stack multiple instances both horizontally and vertically.
//vertical stack ->viewBox = 0, 0, 10*1, 7*2
<svg viewBox="0 0 10 14">
<use href="#Atom"/>
<use href="#Atom" y="7"/>
</svg>
//horizontal stack ->viewBox = 0, 0, 10*2, 7*1
<svg viewBox="0 0 20 7">
<use href="#Atom"/>
<use href="#Atom" x="10"/>
</svg>
//"diagonal" stack ->viewBox = 0, 0, 10*2, 7*2
<svg viewBox="0 0 20 14">
<use href="#Atom"/>
<use href="#Atom" x="10"/>
<use href="#Atom" y="7"/>
</svg>
The first stacking example has two symbols placed vertically, with the same viewBox dimensions as the symbol but with double the height from 7 to 14. This works perfectly.
In the second example, there are two symbols stacked horizontally, maintaining the same viewBox dimensions as the original symbol but doubling the width from 10 to 20. This also works correctly.
However, in the third example with two symbols stacked both horizontally and vertically, setting the viewBox width and height to be twice the original does not work properly. https://i.stack.imgur.com/kKiPS.png
As shown in the image, the symbols overlap (indicating a potential issue with the viewBox).
Here is an example of what I am trying to achieve (note that overflow: visible is used, causing the symbols to extend beyond the viewBox).
https://i.stack.imgur.com/cQTO0.png
Could someone please clarify where I might be going wrong with this? Any assistance would be greatly appreciated.
For anyone interested in experimenting with this, here's the codepen link.