HTML:为什么输入字段 SIZE 没有被弃用?我们有 style=“width:xx”!
简而言之,我认为输入“size”字段现在已经过时(就像 css 之外的 html 样式的其余部分一样),并且大多数大小调整属性已被弃用,那么为什么不弃用 input.size 呢?
simply put, i think that the input 'size' field is now obsolete (like the rest of html styling outside of css), and most of the sizing attributes have been deprecated, so why not input.size?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
也许您对
size
和width
/height
属性感到困惑(顺便说一句,当您说字段时,我一开始感到困惑)。但假设您没有,让我解释一下size
的用途。size
属性元素
的属性
size
适用于文本输入,如电子邮件、密码等。It定义输入的最大字符宽度。举例来说,您希望最大密码长度为 4 来欺骗用户,您给它size=4
,这样您就无法输入像 dinosaur 这样的密码(您输入的任何内容) dino 之后不会出现,除非你先删除前面的字母)编辑:正如 Maksym 在评论中指出的,上面的定义是
最大宽度
,不是大小
。size
是,如果我们参考 HTML4 规范,所以
size=4
大约是 4 个(等宽?)个字符宽(我对 Google Chrome 的实验使它变成了size+1
,即size=4
code> 为 5 个字符宽。)尺寸属性
现在以尺寸属性
width
和height
为例。对于元素,它们仅适用于图像按钮。它们定义按钮的尺寸。现在为什么不能直接对它们应用 CSS 呢?
首先,要知道 CSS 是用于视觉目的的。图像按钮提交用户单击的坐标。此行为需要在各个浏览器之间保持一致,无论它们是否支持 CSS。请参阅此变形图像:
可能存在以下情况:用户被要求点击字母e以使表单提交得到不同的处理。服务器可能会检查 x 坐标是否为
75 <= x <= 90
。但是,如果您使用 CSS 定义尺寸,则禁用 CSS 的浏览器将看到此图像:以及上一个坐标范围检查不再有效,看到字母 e 更靠右,几乎不在 75 和 90 之内(并且您需要单击第一个
o 的左侧) code> 以获得相同的输入)。
Maybe you got confused between
size
andwidth
/height
attributes (btw I got confused at first when you said field). But assuming you didn't, let me explain whatsize
is for.size
attributeThe attribute
size
for element<input>
applies to text inputs, like e-mail, password, etc.It defines the maximum character width for the input. Let's say for example you want the maximum password length to be 4 to screw the users, you give itsize=4
, so you cannot enter passwords like dinosaur (anything you type after dino will not appear unless you delete the previous letters first)Edit: as pointed out by Maksym in the comments, the above is defined by
maxwidth
, notsize
.size
is, if we refer to HTML4 spec,So
size=4
is about 4 (monospaced?) characters wide (My experiment with Google Chrome has makes itsize+1
though, i.e.size=4
is 5 characters wide.)Dimension attributes
Now in case of the dimension attributes
width
andheight
. For<input>
elements, they apply only to image buttons. They define the dimensions of the button. Now why can't you just apply CSS to them?First, know that CSS is for visual purposes. Image buttons submit coordinates that the user clicked on. This behavior needs to be consistent across browsers, whether they support CSS or not. See this warped image:
There may be a case where the user is asked to click the letter e for the form submit to be processed differently. Probably the server will check whether the x coordinate is
75 <= x <= 90
. But if you defined the dimension with CSS, browsers which disabled CSS will see this image instead:And the previous coordinate range check is no longer valid, seeing that the letter e is further to the right, hardly within 75 and 90 (and you need to click on the left side of the first
o
to get the same input).这实际上是一个反问句……或者是试图进行有说服力的论证。不过,你是对的——它很容易被弃用并由 CSS 取代。至于为什么,这个答案只能来自 W3C 内部参与决策过程的人。您还可能会问为什么表格中不推荐使用 cellpadding、cellspacing 和 width 属性。
That is a rhetorical question really... or an attempt at persuasive argument. You are right, though-- it could easily be deprecated and CSS take over. As for why, that answer can only come from someone inside W3C who is part of the decision making process. You could also ask why cellpadding, cellspacing, and width properties are not deprecated in tables.
对于您的非问题,我可以给您的最佳答案是 HTML 不是一种纯粹的语言 - 虽然它回到了它的根源:只是内容而不是样式或行为,但它仍然具有它是 90 年代和 00 年代的遗产,这意味着它仍然存在超出内容的担忧。
The best answer I can give you to your non-question is that HTML isn't a purist language--while it's getting back to it's roots of being just content and not style or behavior, it still has it's legacy from the 90's and 00's, which means it still has concerns beyond just content.
不建议弃用此属性是有充分理由的:“Web 可用性”
当用户查看您的网站时,考虑到 CSS 已关闭或不可用,让用户看到长字段,而实际上,该字段只需要几个字符(例如 ID、电话号码等)。
是的,CSS 很好,但前提是您也考虑到那些无法使用它们的人。
There's a valid reason why this attribute isn't deprecated: "Web Usability"
When a user views your site, considering the CSS is turned of or unavailable, it's really a bad idea to let the person see a long field while in fact, the field only requires a few characters (such as ids, phone numbers, etc.).
CSS is good, yes, but only if you also considered people who won't be able to use them.