2016-01-22 76 views
3

我試過這個http://jsfiddle.net/helderdarocha/e4bAh/。但它只是水平居中。這是代碼和的jsfiddle:如何在SVG g元素中居中文本?

<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> 

如何中心.pointIndex裏面.point

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

回答

4

最後的問題是與y="50"text.pointIndex,將其更改爲y="5"讓它垂直居中

JS Fiddle - updated

.point circle { 
 
    cursor: pointer; 
 
    text-align: center; 
 
    fill: #E2137E; 
 
    r: 10; 
 
    stroke: #333; 
 
    stroke-width: 2px; 
 
}
<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>

+0

對不起,我想中心'.point索引不是'.deletePoint'。 – alexchenco

+0

由於有從1到10的數字。我需要找到一個以像素爲中心的非像素方式。 – alexchenco

+0

無法在地圖上找到'.pointIndex',一定是我的眼睛 –