Making every character on a web page the same width

前端 未结 7 1291
面向向阳花
面向向阳花 2020-12-05 17:43

Is there a font or CSS property that would give every character the same width without the need of drawing them yourself(.ttf)?

相关标签:
7条回答
  • 2020-12-05 17:57

    How about Courier New? monospace?

    http://www.ampsoft.net/webdesign-l/WindowsMacFonts.html

    0 讨论(0)
  • 2020-12-05 17:58

    For certain cases, using the pre tag,(<pre>text</pre>), might fill your needs for monospaced (fixed width) text. It worked for me with HTML5 + Chrome (current version). The ttelement is deprecated.

    However it appears the <pre> tag can only contain tags which are considered "phrasing content". See "Content model" section on the w3 documentation for that tag. You can click the link to see what elements are considered "phrasing content". Of course, each browser may support a looser version of the spec if you don't care about valid HTML or cross browser compatibility.

    0 讨论(0)
  • 2020-12-05 18:07

    You could chose from any of the freely available fixed width fonts and embed them in your site.

    If you don't want to embed a font in your page, you could use the following to take whatever monospace (another term for fixed width) font is available:

    font-family: "Courier New", Courier, monospace;
    
    0 讨论(0)
  • 2020-12-05 18:08

    Another option would be to use lettering.js, which would create a span element around each letter that you could then set a width to with css. This would probably only be advisable for small texts, though.

    0 讨论(0)
  • 2020-12-05 18:17

    There's a number of monospaced fonts that give equal width to each character. Courier and Courier New are probably the most common, and should be available on pretty much every system.

    0 讨论(0)
  • 2020-12-05 18:20

    If you only need numbers to be equal widths, you can use font-variant-numeric: tabular-nums;. It's really useful for animating counters. Read more about it on Mozilla web docs.

    0 讨论(0)
提交回复
热议问题