this is not brute force;)
HTML:
<span id="txt">Lorem</span> <div id="card"></div>
CSS
#card { width: 150px; height: 50px; border: 1px solid black } #txt { display: none }
JS (using jQuery):
var size_w = (150/$('#txt').width() - 0.05); var size_h = (50/$('#txt').height() - 0.05); var size = size_w>size_h?size_h:size_w; $('#card').css('font-size', size + 'em'); $('#card').text($('#txt').text());
fiddle here: http://jsfiddle.net/cwfDr/
Ok, now it covers both height and width .;)
marines
source share