HTML / CSS - adjust font-size to fill parent height and width

前端 未结 5 1038
梦毁少年i
梦毁少年i 2020-12-03 11:04

I have a

element that resizes as the browser window resizes.

Inside the

I have a paragraph of text:



        
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 11:54

    fittext.js did not work correctly for me (plugin for jQuery, as well as derived jquery-free version), nor with using of compressor attribute, so I found another solution:

    http://www.dhtmlgoodies.com/?whichScript=text_fit_in_box (someone's another work)

    which works perfectly for me - longer texts as well as shorter texts.

    It just do not react to resize of window (it works just once on loading of page), so I have written this short code to run it automatically after each window resize (it works for me):

    
    

    I hope it can help to someone.

提交回复
热议问题