English 中文(简体)
如何计算包括左边和左边在内的全部宽度
原标题:How to calculate total width of text including the left and right bearing

我试图以超文本计算整个宽度,包括第一个和最后特性的左侧和正确带。 我已经尝试了Javascript sack Width和jQuery sidth &外阴部功能,但都没有回过我所寻求的正确价值。 这里是example。 计算出的宽度为135px,同时测量网络开发商笔,实际宽度为141px。

<><>Edit>/strong>

Here is what I ve tried, and here are the values it gives me: offsetWidth = 135 jQuery.width() = 135 jQuery.outerWidth() = 135

他们当中没有一个人正在计算负起的6px(这将导致第141条)。

最佳回答

可悲的是,不存在任何直截了当的解决办法,因为it不在“”的盒子门面——浏览器本身并不承认该信在布局时的过份。 如果您在<条码>和<条码>中填上<>;span>, 可在<条码>上填写<条码>、>、div><条码>上填写<条码>width: 135px和over: auto 纽约总部 似乎没有任何滚动障碍,hang被完全切断。 因此,火力大火也报道了没有高压的宽度。

As @Aaron pointed out, the problem doesn t exist with monospaced fonts as no letters extend beyond the character s fixed-width box in those fonts.

找到真正的宽度的唯一途径是采用基于六氯(而不是基于布局的)方法。 我可以想到一种方式:用同样的字体将同一案文放在<代码><canvas>要素上,并用这一方式衡量皮条。

问题回答

Actually, I think the problem is the font itself. I changed the jsfiddle to font-family: monospace, and it was all contained within the grey box (and calculated correctly, as a result). Even leaving it as the original font, but changing the sample to "aaa" or "mmmm" worked great. It s just the "f" glyph in that font that s blowing it for you.

不幸的是,我不知道一个DOM称了这一点。 不能肯定答案很多,但我没有机会就这一问题发表意见,认为这些结论可能有助于你正确方向......

How about jQuery s .width(?

<span id="spanId"> ... </span>

以及

var w = $( #spanId ).width();




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签