I need to scale a svg (referenced with <use>
) around its center that also effect the size of the parent. ( the parent has to be absolute positioned )
The setup looks like this:
<div class="parent">
<svg class="visual" viewBox="0 0 30 30" width="30">
<use href="#ref" />
</svg>
</div>
Tried the following appraches:
- scale by width/height property on the svg element – scale from 0, 0 instead of center ( width )
- scale by "scale" on svg – parent doesnt scale with child ( scale )
I also tried to translate the origin to the center but it seems that svg doesnt work like this ( most is cutoff ).
The goal is to scale the svg reference at the center without effecting the parent style ( like border ) but effecting the parent size.
2
Answers
Not sure if I got you correctly but if you want the parent to scale up based on the child you can give the parent
display:inline-block;
style:You can change the cog size from the center absolute positioning to
top: 50%; left: 50%;
and translating the element -50% on the X and Y axis. Here is an example, the svg changed its size from the center on hover :