为什么svg中的文字不显示?

hig*_*dth 7 svg

我有一个简单的svg元素,

<svg height="100" width="710">
  <rect width="700" height="50"/>
    <rect width="70" height="50" style="fill: rgb(0, 0, 255);">
      <text y="0" style="fill: white;">-0.123994</text>
    </rect>
    <rect width="70" height="50" style="fill: rgb(255, 0, 0);" transform="translate(630,0)">
    <text y="50">0.387869</text>
  </rect>
</svg>
Run Code Online (Sandbox Code Playgroud)

为什么不text显示任何一个元素?这就是它所显示的: 在此输入图像描述

Smi*_*ita 13

你不能把text标签放在里面rect.如果要在rect元素中显示文本,则应将它们放在一个组中.

<svg height="100" width="710">
    <g>
    <rect width="70" height="50" style="fill: rgb(0, 0, 255);"></rect>
      <text y="0" style="fill: white;">-0.123994</text>
    </g>
    <g>
    <rect width="70" height="50" style="fill: rgb(255, 0, 0);" transform="translate(630,0)"></rect>
    <text y="50">0.387869</text>
   </g>

</svg>
Run Code Online (Sandbox Code Playgroud)

请调整文本的坐标以显示在rect中.