问题描述
我复制了下面的倒数第二个 HTML 代码片段表单 here,并通过在文本中添加 <p>uffa</p>
对其进行了编辑。如您所见,uffa
显示在页面底部而不是曲线上。这是为什么?我可以在 textPath
标签中放入什么以使其遵循曲线?
<svg viewBox="0 0 500 500">
<path id="curve" d="M73.2,148.6c4-6.1,65.5-96.8,178.6-95.6c111.3,1.2,170.8,90.3,175.1,97" />
<text width="500">
<textPath xlink:href="#curve">
Dangerous Curves Ahead <p>uffa</p>
</textPath>
</text>
</svg>
解决方法
p
不是 SVG element,因此它被放置在 SVG 视图框之外。或者,您可以使用 tspan
来定义 <text>
<svg viewBox="0 0 500 500">
<path id="curve" d="M73.2,148.6c4-6.1,65.5-96.8,178.6-95.6c111.3,1.2,170.8,90.3,175.1,97" />
<text width="500">
<textPath xlink:href="#curve">
Dangerous Curves Ahead <tspan>uffa</tspan>
</textPath>
</text>
</svg>