Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a inline text in SVG with different sizes?

Tags:

svg

It's quite easy to create a text with different font sizes for different words in HTML. But what about <text> in a svg?

I think this explains quite well about my question: https://jsfiddle.net/4atoctra/1/

Everything's here below:

<div>
This is a text, and you can have <span style="font-size:25px">big</span> and <span style="font-size:11px">small</span> sizes easily inline.
</div>

<div style="margin-top:50px">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="none" x="0px" y="0px" width="360px" height="126px" viewBox="0 0 360 126">
<text><tspan x="150" text-anchor="middle" y="10" font-family="Tahoma" font-weight="bold" font-size="11" fill="#003863" xml:space="preserve">What about this in a &lt;svg&gt;?</tspan></text></svg>
</div>
like image 905
AGamePlayer Avatar asked Oct 20 '16 12:10

AGamePlayer


1 Answers

You can just change the font-size on each tspan element?

<svg viewBox="0 0 500 100" width="500px">
  <text x="0" y="50" font-size="20">It's not <tspan font-size="30">that hard</tspan><tspan font-size="40"> to change size?</tspan></text>
</svg>
like image 162
Persijn Avatar answered Sep 24 '22 13:09

Persijn