innerHTML文字的宽度和高度 [英] innerHTML text width and height

查看:167
本文介绍了innerHTML文字的宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



是否可以测量innerHTML文本的像素大小?

我想显示文字的高度和宽度.
我用"offsetWidth"和"offsetHeigth"进行了尝试,但是然后您得到了fontframe的尺寸:
http://www.stickers.be/Forum-Images/span.jpg [ ^ ]


取下您的图形编中的文字并进行测量.
然后将文本分开(转换为轮廓).那是我需要的高度.
参见示例:
http://www.frogstyling.be/textoutlines.jpg [

Hi,

Is it possible to measure the pixelsize of an innerHTML text?

I want to show the height and width of text.
I tried it with "offsetWidth" and "offsetHeigth", but then you get the dimensions of the fontframe :
http://www.stickers.be/Forum-Images/span.jpg[^]


Take the text in your drawing prog and measure it.
Then break the text apart (convert to outlines). That''s the height I need.
See example :
http://www.frogstyling.be/textoutlines.jpg[^]

推荐答案

看看下面的链接.它可能只是一种样式,使您无法正确进行测量.您可以尝试一下看看.
http://chamnapchhorn.blogspot.com/2008/06/determine-real-offsetwidthoffsetheight.html [ ^ ]

另外,也许这个错误报告可以对您有所帮助(
):
http://www.quirksmode.org/bugreports/archives/2005/08/Wrong_offsetWidth_in_Mozilla_and_Opera.html [ ^ ]

祝您好运!
Have a look at the link below. It just might be a style that prevents you from measuring correctly. You could try it and have a look.
http://chamnapchhorn.blogspot.com/2008/06/determine-real-offsetwidthoffsetheight.html[^]

Also, maybe this bug report can help (with the work around given):
http://www.quirksmode.org/bugreports/archives/2005/08/Wrong_offsetWidth_in_Mozilla_and_Opera.html[^]

Good luck!


如果您检查DOM,则可能会找到对特定元素有效的字体,然后以这种方式确定高度.
If you check the DOM, you can probably find the font that is in effect for the particular element, and then determine the height that way.


这篇关于innerHTML文字的宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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