It's strange that I couldn't find anyone else reporting this problem; that makes me think perhaps I am doing something wrong.
I have a <style>
tag within an SVG that contains a :hover
pseudo-class, it works properly when the SVG is directly embedded into the HTML, but when I put it within a symbol and reference it with a <use>
tag, the styles inside the <style>
tag are not applied.
SVG Directly-embedded:
<svg width="400" height="110">
<style>
#myRect:hover {
fill: red;
}
</style>
<rect id="myRect" width="300" height="100" />
</svg>
Defined in a symbol, and referenced via the <use>
tag.
<svg style="display: none">
<symbol id="rectangle">
<style>
#myRect:hover {
fill: red;
}
</style>
<rect id="myRect" width="300" height="100" />
</symbol>
</svg>
<svg width="400" height="110">
<use href="#rectangle"></use>
</svg>
Why is this happening?! Seems like a weird behavior, am I missing something?!
UPDATE: As Temani Afif mentioned in the comments, this problem exists only in Chrome, Firefox seems to work as expected. (Haven't tested on any other browsers)