Center (proportional font) text in an HTML5 canvas

后端 未结 5 1297
别那么骄傲
别那么骄傲 2020-12-18 19:41

I would like to be able to center single lines of text within rectangular areas I can calculate. The one thing I have expected to do in 2D geometry on a canvas is to center

5条回答
  •  温柔的废话
    2020-12-18 20:16

    What you do is render your text off-screen using a negative text-indent, then grab the size.

    text-indent: -9999px
    

    See: hiding text using "text-indent"

提交回复
热议问题