I have a code in SVG:
<svg width="100%" height="100%" version="1.1"xmlns="http://www.w3.org/2000/svg">
<rect x="20" y="20" width="250" height="250" style="fill:blue">
<animate attributeType="CSS" attributeName="opacity" from="1" to="0" dur="5s" repeatCount="indefinite" />
</rect>
</svg>
Now I need to add a text between this rectangle
. Can anyone tell me how to do it?
If you want to display text inside a rect element you should put them both in a group with the text element coming after the rect element ( so it appears on top ).
SVG Text - <text> The <text> element is used to define a text.
I am not sure what you mean by "between". If you mean "centered horizontally and vertically", then this would do it:
<svg width="100%" height="100%" version="1.1" xmlns="http://www.w3.org/2000/svg">
<rect x="20" y="20" width="250" height="250" style="fill:blue" />
<text x="145" y="145" text-anchor="middle" alignment-baseline="middle">
Hello World
</text>
</svg>
Did you mean something else?
If you are talking about having text filling the rectangle—multiple lines of text wrapping at the edges of the rectangle onto a new line—then you should see this Stack Overflow question instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With