TL;DR
Having created symbol-svg-sprite
and inserting its fragment using svg+use
, I want to use css-variables
inside #ShadowDOM for SVG presentation attributes
to change for example stroke-width="0"
in stroke-width="5"
, and the transition property
must work, the problem is that the stroke-width
values work at any event (:hover :active :focus) and transition
does not.
External SVG sample
<svg style='display:none;' xmlns="http://www.w3.org/2000/svg">
<symbol id='symbol-id' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 23 20">
<path style='transition-duration: var(--custom-duration); transition-property: var(--custom-property);' stroke="var(--custom-stroke)" stroke-width="var(--custom-stroke-width)" fill="cyan" d="long..."
</symbol>
</svg>
Insert SVG+USE
<svg>
<use class="use-class" xlink:href="../transition-error.svg#symbol-id"></use>
</svg>
Applied CSS style
svg
outline 1px solid black
width 250px
height 250px
.use-class
--custom-stroke-width 0
--custom-duration .5s
--custom-property all
.use-class:hover
--custom-stroke-width 2
--custom-stroke blue
--custom-duration 2500ms
--custom-property all
Expected behavior
When you hover the svg container, the values of the variables change and stroke stroke-width 0
smoothly flows into stroke-width 2
— this happens but without transition
although transition
assigned to <path>
this can be seen in
DevTools
Where does this work?
- Inline svg through tag
<svg>
—<svg> <path d="..."> </svg>
- Using tag
<object></object>
with external css
Demonstration can be seen on CodePen
How to make CSS transition
work for external-svg-sprites
? I'm tired of fighting this :(