gpt4 book ai didi

javascript - 在 SVG 路径内垂直/水平居中文本

转载 作者:行者123 更新时间:2023-11-28 04:32:30 25 4
gpt4 key购买 nike

我想将文本垂直/水平居中放置在由 SVG Path 元素制作的矩形内。

中心并不是指将第一个字母放在矩形的中心,而是将文本的中心放在路径的中心。

这是我的代码结构:

<svg id="shape">
<path id = "a" d="M 0 0 L 100 0 L 100 100 L 0 100 Z"></path>
<text>
<textPath xlink:href="#a">My Text</textPath>
</text>
</svg>

最佳答案

我已经通过这样做来实现这一目标:

<svg id="shape">
<path id = "a" d="M 0 0 L 100 0 L 100 100 L 0 100 Z"></path>
<text x="50" y="50" text-anchor="middle" alignement-baseline="middle">My Text</text>
</svg>

关于javascript - 在 SVG 路径内垂直/水平居中文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44512260/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com