在SVG中绘制的矩形之间插入文本

Mav*_*ick 16 html animation svg text

我在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>
Run Code Online (Sandbox Code Playgroud)

现在我需要在此之间添加一个文本rectangle.谁能告诉我怎么做?

Phr*_*ogz 19

我不确定你的意思是"之间".如果你的意思是"水平和垂直居中",那么这样做:

<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>
Run Code Online (Sandbox Code Playgroud)

你的意思是什么?

如果您正在讨论将文本填充矩形 - 多行文本包装在矩形的边缘上的新行 - 那么您应该看到此Stack Overflow问题.