为html输入文本指定3个字符的宽度 [英] Specify width of 3 chars for an html input text

查看:44
本文介绍了为html输入文本指定3个字符的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建一个完全可以容纳3个字符的 HTML 文本框?
我在网上找到了此代码:< input type ="text" style ="width:10px; padding:2px; border:1px纯黑色"/>
它创建一个宽度为10px的文本框.我可以使用它,但是我想知道我们是否可以显式设置3个字符的宽度,而不是玩"像素,

How would I create an HTML text box that exactly 3 characters can fit into it?
I found this online: <input type="text" style="width: 10px; padding: 2px; border: 1px solid black"/>
It creates a text box with width of 10px. I could use this but I was wondering if we could explicitely set for 3 chars width instead of "playing" with pixels,

推荐答案

不可靠,因为l和W的宽度非常不同.

Not reliably, since l and W have very different widths.

但是,如果将字体设置为 monospace ,则将有所帮助.然后,您应该能够在输入元素上设置 size ="3" ,并且理论上它应该恰好是三个字符宽.

However, if you set the font to monospace, that helps. Then, you should be able to set size="3" on the input element, and in theory it should be exactly three characters wide.

这篇关于为html输入文本指定3个字符的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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