0
当CSS高度设置为Auto时,如何获得充满文本的div对象的完整高度?当高度为自动时,jQuery OuterHeight/Height会返回错误的高度值
我试过OuterHeight,它仍然不是div对象的完整高度。
的jsfiddle:https://jsfiddle.net/zerolfc/jg8s5oq3/3/
的jQuery:
$('div').find('*').each(function(ti,tv){
var c = parseInt($(tv).css('font-size'))/2;
c = Math.floor(c);
c = (c < 8 ? 8 : c);
$(tv).css('font-size', c + 'px');
});
console.log($('div').outerHeight(true));
CSS:
div { display: block; width: 640px; height: auto; }
p { font-size: 24px; }
HTML:
<div>
<p>This is a textbox that you can add text to suit your design and alter.This is a textbox that you can add text to suit your design and alter.</p>
<p>This is a textbox that you can add text to suit your design and alter.This is a textbox that you can add text to suit your design and alter.</p>
<p>This is a textbox that you can add text to suit your design and alter.This is a textbox that you can add text to suit your design and alter.</p>
<p>This is a textbox that you can add text to suit your design and alter.This is a textbox that you can add text to suit your design and alter.</p><p>This is a textbox that you can add text to suit your design and alter.This is a textbox that you can add text to suit your design and alter.</p><p>This is a textbox that you can add text to suit your design and alter.This is a textbox that you can add text to suit your design and alter.</p>
</div>
返回拨弄我的正确值。 – Goombah
http://imgur.com/a/AXATT – Goombah
在控制台窗口中,我得到了与你相同的228像素,但是在检测div时为252像素,它在Chrome中返回252像素的高度(尺寸工具提示)? – tonoslfx