How to get the width of an SVG tspan element

后端 未结 2 2035
悲&欢浪女
悲&欢浪女 2021-01-12 07:40

I\'m trying to get the rendered width of a tspan element (located inside a text element) in SVG.

This is my markup:



        
2条回答
  •  走了就别回头了
    2021-01-12 08:00

    After trying multiple solutions I found getComputedTextLength to be the most accurate way to get the width of an svg tspan. It is also well supported and behaves the same way on different browsers. I also found that the best way to get the height of a tspan is simply to read the font-size attribute.

提交回复
热议问题