dynamically changing the size of font size based on text length using css and html

前端 未结 8 1263

I need to display user entered text into a fixed size div. What i want is for the font size to be automatically adjusted so that the text fills the box as much as possible.<

8条回答
  •  生来不讨喜
    2020-12-08 05:00

    If by text length you mean character count, there is this article which points to a short jquery snippet Change Font Size dynamically based on Character count

    http://jsfiddle.net/jfbrLjt2/

     $('.text').each(function(){
     var el= $(this);
       var textLength = el.html().length;
        if (textLength > 20) {
            el.css('font-size', '0.8em');
        }
    });
    

提交回复
热议问题