What dependency between font-size and width of char in monospace font?

前端 未结 3 802
天涯浪人
天涯浪人 2021-02-07 15:15

What dependency between font-size and width of char in monospace font? In my web-application I use \"courier new\" font. I want to know, what realy length in pixels of string? I

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-07 15:58

    The dependency between the font-size and the width of characters (glyphs) in a monospace font is defined by the font designer.

    For example, on Windows 7, the advance width of glyphs in the Courier New font is 1229 units. Since the height of the font is 2048 units, the advance width is thus very, very close to 60% of the font size, so in CSS, 0.6em would be an adequate quantity for the width of glyphs for all practical purposes.

    In Lucida Console, the advance width is almost the same: 1234 units. But in Consolas, on the other hand, it is considerably smaller, 1126 units.

    The conclusions thus depend on the context, especially on the question whether your application is meant to be run only in situations where a specific font is available (and your settings won’t be overridden by users).

提交回复
热议问题