Fit text perfectly inside a div (height and width) without affecting the size of the div

前端 未结 9 1852
盖世英雄少女心
盖世英雄少女心 2020-12-02 17:07

I apologise in advance as I know this question has come up many times before but I just can\'t seem to find the right solution (and believe me I\'ve tried a few!)

Ba

9条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 17:59

    I don't have enough reputation to comment on the accepted answer so I made an answer. If height has a css3 transition on it the autoSizeText() and $.resizeText answers above have issues. I made a short jquery plugin to fix this.

    $.fn.resizeText = function (options) {
    
        var settings = $.extend({ maxfont: 40, minfont: 4 }, options);
    
        var style = $('