确定每行给定宽度的字符数(基于font-size,font-family) [英] Determine the number of characters per line given a width (based on font-size, font-family)

查看:152
本文介绍了确定每行给定宽度的字符数(基于font-size,font-family)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以根据font-sizefont-family等参数确定给定宽度div的每行字符数? 请为此提供跨浏览器解决方案或抢先一步.

Is there a way we can determine the number of characters per line for a given width of div based on parameters like font-size, font-family, etc? Please give a cross browser solution or a head start regarding this.

注意:我有一个宽度可变的文本区域,因此限制每行的字符数或涉及列和行的解决方案不是我要的解决方案.

Note: I have a text area whose width is variable so limiting the number of characters per line or solution involving columns and rows is not the solution I'm looking for.

推荐答案

除非您正在谈论等宽字体*,否则如果不考虑所涉及的特定文本,就无法知道此答案.作为一个基本示例,请注意以下两者之间的区别:

Unless you're talking about a monospace* font, this answer isn't knowable without taking into consideration the specific text in question. As a basic example, note the difference between:

  • 10 MONOSPACE X's XXXXXXXXXX
  • 10 MONOSPACE I's IIIIIIIIII
  • 10 VARIABLE X's_ XXXXXXXXXX
  • 10 VARIABLE I's_ IIIIIIIIII
  • 10 MONOSPACE X's XXXXXXXXXX
  • 10 MONOSPACE I's IIIIIIIIII
  • 10 VARIABLE X's_ XXXXXXXXXX
  • 10 VARIABLE I's_ IIIIIIIIII

对于宽度可变*字体,相同字体中相同数量的字符可以是两个不同的宽度. (因此命名)

With a variable-width* font, the same number of characters, in the same font, may be two different widths. (hence the name)

* 术语等宽字体",固定宽度",固定间距"或非比例"字体是一种其字符各自占据相同数量水平空间的字体.相反,比例"或可变宽度"字体包含的字符宽度可能会占用不同的水平空间.

这篇关于确定每行给定宽度的字符数(基于font-size,font-family)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆