<div style="width: 50px;">
<div id="theElement" style="position: relative; left 25px;">textMuchLongerThan50[</div>
</div>
document.getElementById("theElement").clientWidth 总是返回 50,这是父元素的宽度,但很明显元素的内容要宽得多
(元素本身实际上有这个宽度,但我需要知道它的“自然”宽度,即其内容的宽度。)
在 Chrome 和 IE 中遇到此行为。如果有人知道如何确定位于另一个具有预设/有限宽度的 DIV 中的相对定位 DIV 的实际尺寸...?
最佳答案
您对scrollWidth感兴趣: Example
关于javascript - clientWidth "lying",无法确定元素的实际宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7728373/