为什么IE和Firefox为div返回不同的溢出维度? [英] Why are IE and Firefox returning different overflow dimensions for a div?
问题描述
我有一个 div
,固定大小为100px。 scrollWidth
和 scrollHeight
正常工作,如果 div
是正常的(没有字长到足以完全填满一行)。但是,如果有一个单词的文本比100px更宽,则会导致问题。假设文本就像ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890那样:Firefox返回错误的 scrollWidth
(在这种情况下为100,即使 div
正在溢出,这与实际宽度相同)。但是,IE正在给出正确的 scrollWidth
(在这种情况下为180)。
请帮助我在Firefox中获得正确的 scrollWidth
。对不起,如果我的问题看起来模糊不清。
确保您的 div
有 overflow:hidden
或 overflow:auto
样式集。如果它是 overflow:visible
(默认值),那么FF将不会计算更大的 scrollWidth
没有滚动(文本全部呈现)。
您使用IE浏览的行为实际上是由于浏览器实现的错误 overflow:visible
。
I have a div
with a fixed size of 100px. scrollWidth
and scrollHeight
works fine if the text in the div
is normal (no word is long enough to fill the one row entirely). However, if there is any text with one word rendering wider than the 100px it will cause a problem.
Let's say the text is like "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890": then Firefox returns the wrong scrollWidth
(100 in this case, which is same as the actual width even though the div
is overflowing). However, IE is giving the correct scrollWidth
(180 in this case).
Please help me get the correct scrollWidth
in Firefox. Sorry if my question looks vague.
Make sure that your div
has the overflow:hidden
or overflow:auto
style set. If it's overflow:visible
(the default), then FF won't calculate a larger scrollWidth
as there's nothing to scroll (the text is all rendered).
The behavior you observed with IE is actually due to a bug in that browser's implementation of overflow:visible
.
这篇关于为什么IE和Firefox为div返回不同的溢出维度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!