Search code examples
jqueryhtmlresizefont-sizeautoresize

Resize Text to Fit DIV--with higher accuracy?


I'd like to fit a block of text into a div by changing the font size automatically.

I've been using this jQuery function,

$(function() {
    while( $('#fitin div').height() > $('#fitin').height() ) {
        $('#fitin div').css('font-size', (parseInt($('#fitin div').css('font-size')) - 1) + "px" );
    }
});

and it works well--except that the accuracy isn't high enough (it lowers the size by 1px every time; I need it to work with much smaller increments, such as .1mm). Am I missing something here?

Thanks--let me know if I haven't included enough info.


Solution

  • From Pixel on Wikipedia,

    In digital imaging, a pixel, pel, or picture element is a physical point in a raster image, or the smallest addressable element in an all points addressable display device; so it is the smallest controllable element of a picture represented on the screen.

    Then, you can't have more precision than a pixel.