In short, you cannot do this because different platforms and browsers create fonts differently.
And there is no cross-browser cross-platform method for calculating font sizes.
Javascript "solution" is to check if the div overflows and then increase its size, something like
while (div.scrollHeight >= div.offsetHeight) { div.style.height = (parseInt(fontSpan.style.fontSize) + 1) + 'px'; }
Ben Nov 09 '10 at 8:53 2010-11-09 08:53
source share