Algorithm for estimating text width based on contents

前端 未结 8 2256
傲寒
傲寒 2021-02-08 09:11

This is a long shot, but does anyone know of an algorithm for estimating and categorising text width (for a variable width font) based on its contents?

For example, I\'d

8条回答
  •  没有蜡笔的小新
    2021-02-08 09:26

    For a nice* client-side solution, you could try a hybrid CSS-and-Javascript approach as suggested by RichieHindle's answer to my question.

    Given that you don't know what font the user will see the page in (they can always override your selection, Ctrl-+ the page, etc), the "right" place to do this is on the browser... although browsers don't make it easy!

    * when I say "nice", I mean "probably nice but I haven't actually tried it yet".

提交回复
热议问题