用javascript计算字母大小 [英] Calculate letter size in javascript
问题描述
我试图使用div元素为此,但此方法只给出div的大小,而不是信。
< div style =display:inline; background-color:yellow; font-size:53px;行高:32PX>一种与LT; / DIV>
有人知道如何解决这个问题吗?
对于一般情况,这基本上是不可能的。字体字距会根据操作系统,浏览器等等导致字母变化的宽度,并且根据哪些字母彼此相邻。如果os +浏览器没有您指定的字体,则可能会发生字体替换。
也许用你所追求的更高层次的目标重新提出这个问题,可能会导致对你的问题提出其他的解决方法,这可能会更有成果? >
I need to calculate the exact size of the letter in javascript. The letter can have different font-size or font-family attributes, etc.
I tried to use div element for this, but this method gives only the size of the div, not letter.
<div style="display: inline; background-color: yellow; font-size: 53px; line-height:32px">A</div>
Does anybody know how to solve this issue?
This is basically not possible for the general case. Font kerning will result in variable "widths" of letters depending on the operating system, browser, etc etc, and based on which letters are next to each other. Font substitution may happen if the os+browser don't have the font you specify.
Perhaps re-asking the question with the higher-level goal you're shooting for might result in proposed other approaches to your problem that might be more fruitful?
这篇关于用javascript计算字母大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!