随着键入更多类型,使 HTML 输入字体大小缩小 [英] Make HTML input font size shrink as more type is typed

查看:37
本文介绍了随着键入更多类型,使 HTML 输入字体大小缩小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 3 个字符的 HTML 文本字段.如果用户键入 4 个字符,我希望缩小字体大小以适应四个字符.

I have an HTML text field that is 3 characters. If the user types 4 characters, I want the font size to shrink so that the four characters will fit.

Acrobat 对表单具有此行为.我想要 HTML 中的这种行为.

Acrobat has this behavior for forms. I want this behavior in HTML.

也就是说,如果我有一个包含 3 个字符的文本字段:

That is, if I have a text field with 3 characters:

用户输入 4,我希望文本缩小:

And the user types a 4, I want the text to shrink:

推荐答案

这在 HTML/CSS 中是不可能的 - 此解决方案使用 JS+JQuery

This is not possible with HTML/CSS - this solution uses JS+JQuery

发现这个:https://github.com/vxsx/jquery.inputfit.js演示:http://vxsx.github.io/jquery.inputfit.js/

<input type="text" name="younameit" id="input">
<script type="text/javascript">
    $('#input').inputfit();
</script>

这篇关于随着键入更多类型,使 HTML 输入字体大小缩小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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