How can I autoscale the font size to fit the contents of a div?

后端 未结 5 1535
广开言路
广开言路 2021-01-04 13:42

I have a div with some text:

With some text in it

How can

5条回答
  •  暖寄归人
    2021-01-04 13:56

    Contrary-wise. You could wrap the text in an interior DIV, measure its width with JavaScript. Test if that width is wider than the parent DIV. Get the current font size, and incrementally move it down 1px at a time until inner DIV's width is less than or equal to the outer DIV's width.

提交回复
热议问题