I am currently working on implementing an SVG sprite sheet using the "symbol" method outlined here.
My HTML code is quite straightforward.
<svg><use xlink:href="/images/iconSprite.svg#camera"/></svg>
Below is a sample symbol extracted from the SVG file:
<symbol viewBox="0 0 24 24" id="clock"><g transform="translate(0 -1028.4)"><path d="M22.085 1035.955 ... </g></symbol>
The issue I am encountering is that setting the width of the SVG element to 64px automatically adjusts the height to 150 pixels. Despite trying different CSS options like height:auto; and height:100%;, the desired aspect ratio is not maintained. I prefer to avoid setting a fixed height (e.g., height:64px;) due to varying icon dimensions. Ideally, the SVG should scale proportionately based on the original aspect ratio, such as a 4:3 icon adjusting to 300px height if the width is set to 400px.
While I've researched scaling SVGs with aspect ratio preservation, most solutions focus on IMG elements rather than inline SVGs or external SVGs used with USE tags.
If anyone has insights into achieving cross-browser compatibility, including IE9+ and Android 4.0+, for dynamically scaling SVGs while maintaining aspect ratio, your input would be greatly appreciated!