使文本适合div [英] Fit text to a div

查看:66
本文介绍了使文本适合div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个固定高度和宽度的div,里面我的文字正在改变。有时它可能是一两个字,有时它可能是一个句子。我需要的是缩小字体大小,使文本适合该div。

I have a div with fixed height and width and inside I have text that is changing. Sometimes it can be a word or two and sometimes it can be a sentence. What I need is to shrink the font size so the text fits to that div.

推荐答案

我有一个想法并且它有效: )这是我的代码

i had an idea and it worked :) here is my code

        $('li').each(function () {
            while ($(this).outerHeight() > 25) {
                var currentFontSize = $(this).css("font-size");
                $(this).css("font-size", (parseFloat(currentFontSize) - 1) + "px");
            }

        });

这篇关于使文本适合div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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