Specify width in *characters*

后端 未结 2 1126
孤城傲影
孤城傲影 2020-12-02 15:06

When using a fixed width font, I\'d like to specify the width of an HTML element in characters.

The \"em\" unit is supposed to be the width

2条回答
  •  难免孤独
    2020-12-02 15:49

    ch unit

    The unit you're looking for is ch. According to the MDN docs:

    ch: Represents the width, or more precisely the advance measure, of the glyph "0" (zero, the Unicode character U+0030) in the element's font.

    It is supported in current versions of major browsers (caniuse).

    Example

    pre {
        width: 80ch; /* classic terminal width for code sections */
    }
    

提交回复
热议问题