Creating a number of SVG files can be made easier by keeping common symbols in one file and importing them into others.
An effective method for achieving this is using the <use>
element:
<use href="common.svg#symbol1" />
However, there may be an issue if the `common.svg` file contains CSS styles that impact an element, as these styles may not carry over to the imported files.
To illustrate this problem, two SVGs have been uploaded on svgur.com:
This file defines a circle with id ball
which is styled with a red border.
<svg width="100" height="100" version="1.1" xmlns="http://www.w3.org/2000/svg">
<style>#ball { stroke:#ff0000; stroke-width:10; }</style>
<circle id="ball" cx="50" cy="50" r="45" />
</svg>
In this file, the circle from the previous SVG is used. However, the border does not appear.
<svg width="100" height="100" version="1.1" xmlns="http://www.w3.org/2000/svg">
<use href="bYv.svg#ball" />
</svg>
Questions:
Could this discrepancy in rendering be a bug in the SVG renderer or is it functioning as designed?
All tested renderers (Chrome, Firefox, Inkscape) produce the same result, indicating that this behavior may be intentional.
Is there any known way to import an element from an external SVG file along with its associated CSS styles, ensuring it retains its appearance from the original document?