我正在使用 SVG 創建一些表格并在其中放置一些文本。我可以使用 SVG 坐標控制文本的位置,但文本長度是可變的,因為它來自某些資料。有什么方法可以獲取文本的長度或其他一些工具來證明它的正確性?
uj5u.com熱心網友回復:
右對齊
將您的文本放在 a textPath, setpathLength=100
https://developer.mozilla.org/en-US/docs/Web/SVG/Element/textPath
startoffset并text-anchor注意定位
使用 lowerstartoffset添加右填充

<svg viewbox="0 0 200 50">
<path id="P" pathLength="100" d="M0 25h200" stroke="blue"/>
<text>
<textPath href="#P"
startoffset="100" text-anchor="end"
dominant-baseline="middle"
fill="green" font-size="14px">Right aligned</textPath>
</text>
</svg>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/432820.html
上一篇:svgxmlns中的URL
