如何在SVG g元素中居中文本?

ale*_*nco 4 css svg

我试过这个http://jsfiddle.net/helderdarocha/e4bAh/.但它只是水平居中.这是代码和JSFiddle:

  <svg width="400" height="400">
    <g class="point" transform="translate(225,217)">
      <circle></circle>
      <text class="pointIndex" y="50">
        <tspan text-anchor="middle">10</tspan>
      </text>
    </g>
  </svg>

 <style>
    .point circle {
      cursor: pointer;
      text-align: center;
      fill: #E2137E;
      r: 10;
      stroke: #333;
      stroke-width: 2px;
    }
 </style>
Run Code Online (Sandbox Code Playgroud)

如何中心.pointIndex.point

https://jsfiddle.net/alexcheninfo/9a112b63/6/

Mi-*_*ity 5

最后问题y="50"在于text.pointIndex,将其改为y="5"使其垂直居中

JS Fiddle - 更新

.point circle {
  cursor: pointer;
  text-align: center;
  fill: #E2137E;
  r: 10;
  stroke: #333;
  stroke-width: 2px;
}
Run Code Online (Sandbox Code Playgroud)
<svg width="400" height="400">
  <g class="point" transform="translate(225,217)">
    <circle></circle>
    <text class="pointIndex" y="5">
      <tspan text-anchor="middle">10</tspan>
    </text>
  </g>
</svg>
Run Code Online (Sandbox Code Playgroud)