不符合输入字段的大小属性 [英] Size attribute for an input field not being honored

查看:204
本文介绍了不符合输入字段的大小属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

直接从W3Schools

Taken directly from W3Schools:


定义和用法size属性指定
输入字段的宽度。

Definition and Usage The size attribute specifies the width of an input field.

对于< input type =text> < input type =password> ,size
属性定义字符数应该是可见的。对于
所有其他输入类型,size定义
像素中输入字段的宽度。

For <input type="text"> and <input type="password">, the size attribute defines the number of characters that should be visible. For all other input types, size defines the width of the input field in pixels.





如果是真的为什么我的字段< input type =textsize =2/> 足够宽以显示5个CAPTIAL MMMMM?

So..

If that is true why is my field <input type="text" size="2"/> wide enough to display 5 CAPTIAL MMMMM's ?

推荐答案

HTML4规范中指定了相同的错误 HTML5规范,Sitepoint,Mozilla开发人员网络和Microsoft的MSDN库。所以它不只是W3Schools的错。

The same "erroneous" information is specified in the HTML4 Spec, the HTML5 spec, Sitepoint, Mozilla Developer Network, and Microsoft's MSDN library. So it isn't just W3Schools' fault.

无论如何,虽然规范说,size属性应该是可见的字符数,大多数网络浏览器已经解决使用

Anyway, while the specs say that the size attribute should be the number of characters visible, most web browsers have settled on using the number of em units, meaning the width of the character of the capital M.

要精确指定以像素为单位的宽度或您选择的任何单位,请使用CSS width属性。

To specify the width precisely in pixels, or any unit of your choice, use the CSS width property.

要回答您更新的问题:它是以CSS样式应用于文本框的默认字体大小的大写字母M的宽度,但是字体大小

To answer your updated question: it's the width of the capital M in the default font size as applied by CSS styling to the text box, but the font size of the text inside the text box is usually smaller.

想要设置一定数量的字符在文本框内吗?您必须切换到固定宽度的字体。

Want to make a set number of characters fit inside the box? You'll have to switch to a fixed width font.

这篇关于不符合输入字段的大小属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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