【问题标题】:Vertically/Horizontally Center Text inside a SVG Path在 SVG 路径中垂直/水平居中文本
【发布时间】:2017-06-13 04:13:15
【问题描述】:

我想在使用 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>

【问题讨论】:

标签: javascript html css svg graphics


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2015-09-25
    • 2020-04-06
    • 2012-03-14
    • 2017-06-28
    • 1970-01-01
    • 1970-01-01
    • 2016-09-11
    • 2021-11-18
    相关资源
    最近更新 更多