Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scale a svg text to fit an exact width or the parent container width [duplicate]

This is likely a very simple question, but how do I get text in SVG to stretch to fit its container?

I don't care if it looks ugly from being stretched too long or high, but it needs to fits its container and be as big as possible.

Thanks

like image 945
Tom Avatar asked Nov 26 '22 01:11

Tom


1 Answers

If you really don't care that the text gets ugly, here's how to fit unknown length text into a known width.

<svg width="436" height="180"
    style="border:solid 6px"
    xmlns="http://www.w3.org/2000/svg">
    <g>
        <text y="50%" textLength="436" lengthAdjust="spacingAndGlyphs">UGLY TEXT</text>
    </g>
</svg>

enter image description here

like image 90
Bemmu Avatar answered Dec 04 '22 07:12

Bemmu