HTML:为什么输入字段 SIZE 没有被弃用?我们有 style=“width:xx”!

发布于 2024-09-07 04:26:15 字数 97 浏览 4 评论 0原文

简而言之,我认为输入“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

半仙 2024-09-14 04:26:15

也许您对 sizewidth/height 属性感到困惑(顺便说一句,当您说字段时,我一开始感到困惑)。但假设您没有,让我解释一下 size 的用途。

size 属性

元素 的属性 size 适用于文本输入,如电子邮件、密码等。 It定义输入的最大字符宽度。举例来说,您希望最大密码长度为 4 来欺骗用户,您给它 size=4,这样您就无法输入像 dinosaur 这样的密码(您输入的任何内容) dino 之后不会出现,除非你先删除前面的字母)

编辑:正如 Maksym 在评论中指出的,上面的定义是 最大宽度不是大小size 是,如果我们参考 HTML4 规范,

除非 type 属性的值为“text”或“password”。在这种情况下,其值指的是(整数)字符数。

所以 size=4 大约是 4 个(等宽?)个字符宽(我对 Google Chrome 的实验使它变成了 size+1 ,即 size=4 code> 为 5 个字符宽。)

尺寸属性

现在以尺寸属性 widthheight 为例。对于 元素,它们仅适用于图像按钮。它们定义按钮的尺寸。现在为什么不能直接对它们应用 CSS 呢?

首先,要知道 CSS 是用于视觉目的的。图像按钮提交用户单击的坐标。此行为需要在各个浏览器之间保持一致,无论它们是否支持 CSS。请参阅此变形图像:

可能存在以下情况:用户被要求点击字母e以使表单提交得到不同的处理。服务器可能会检查 x 坐标是否为 75 <= x <= 90。但是,如果您使用 CSS 定义尺寸,则禁用 CSS 的浏览器将看到此图像:

以及上一个坐标范围检查不再有效,看到字母 e 更靠右,几乎不在 75 和 90 之内(并且您需要单击第一个 o 的左侧) code> 以获得相同的输入)。

Maybe you got confused between size and width/height attributes (btw I got confused at first when you said field). But assuming you didn't, let me explain what size is for.

size attribute

The 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 it size=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, not size. size is, if we refer to HTML4 spec,

except when type attribute has the value "text" or "password". In that case, its value refers to the (integer) number of characters.

So size=4 is about 4 (monospaced?) characters wide (My experiment with Google Chrome has makes it size+1 though, i.e. size=4 is 5 characters wide.)

Dimension attributes

Now in case of the dimension attributes width and height. 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).

与酒说心事 2024-09-14 04:26:15

这实际上是一个反问句……或者是试图进行有说服力的论证。不过,你是对的——它很容易被弃用并由 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.

且行且努力 2024-09-14 04:26:15

对于您的非问题,我可以给您的最佳答案是 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.

情话难免假 2024-09-14 04:26:15

不建议弃用此属性是有充分理由的:“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文