SVG文本在中心周围旋转

Cod*_*eak 3 jquery-svg

我有textContent"Design"和text-anchor作为开头的文本,用css转换为45度旋转.所以它旋转了.问题是我需要调整旋转后文本的(x,y)位置,以显示勾选之间的文本,如预期图中所示.我怎样才能做到这一点.

结果:http: //imageshack.us/content_round.php?page = done&l = img404/2711/result1h.png

预期:http://imageshack.us/content_round.php?page = done&l = img266 / 5138 / expected1.png

    <svg>
    <text x="100" y="100" width="64" height="16" fill="black" transform="rotate(45,100,100)" text-anchor="start">Design</text>
    </svg>
Run Code Online (Sandbox Code Playgroud)

谢谢Gowri

Min*_*uel 8

文本需要水平和垂直居中,因此旋转不会移动它:

<text x="100" y="50" text-anchor="middle"
    dominant-baseline="central" transform="rotate(0, 100, 50)"></text>
Run Code Online (Sandbox Code Playgroud)

text-anchor水平
dominant-baseline对齐文本垂直对齐文本

svg {
    width: 200px; height: 100px;
    text-align: center;
    border: solid 1px blue;
    font-family: monospace;
}
Run Code Online (Sandbox Code Playgroud)
<svg>
    <text x="100" y="50" text-anchor="middle" dominant-baseline="central" transform="rotate(180, 100, 50)">
       Hello World
   </text>
    <text x="100" y="50" text-anchor="middle" dominant-baseline="central" transform="rotate(0, 100, 50)">
       Hello World
   </text>
</svg>
Run Code Online (Sandbox Code Playgroud)

示例:http://jsfiddle.net/e4bAh/131/

  • 比我在其他地方看到的每个答案都简单得多,而且它是最准确的!谢谢jsfiddle (2认同)

小智 5

transform="rotate(45, cx, cy)"

cx, cy屏幕中心(或旋转)的坐标在哪里。

这是一个很好的例子

  • 问题是确定 svg 文本的中心。 (2认同)