我试过这个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?
最后问题y="50"在于text.pointIndex,将其改为y="5"使其垂直居中
.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)