如何自动缩放字体大小以适合div的内容? [英] How can I autoscale the font size to fit the contents of a div?

查看:189
本文介绍了如何自动缩放字体大小以适合div的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div与一些文本:

I have a div with some text:

<div style="white-space:nowrap;overflow:none;width:50px;">
  With some text in it
</div>

如何缩放文本的字体大小,使所有文本都可见?

How can I scale the font size of the text so all of the text is visible?

推荐答案

相反。您可以将文本包装在内部DIV中,使用JavaScript测量其宽度。测试该宽度是否宽于父DIV。获取当前字体大小,并逐步将其下移1px,直到内部DIV的宽度小于或等于外部DIV的宽度。

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.

这篇关于如何自动缩放字体大小以适合div的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆