开发者

HTML: why isn't the input field SIZE deprecated? we have style="width:xx"!

开发者 https://www.devze.com 2023-01-05 08:04 出处:网络
simply put, i think that the input \'size\' field is now ob开发者_如何学编程solete (like the rest of html styling outside of css), and most of the sizing attributes have been deprecated, so why not in

simply put, i think that the input 'size' field is now ob开发者_如何学编程solete (like the rest of html styling outside of css), and most of the sizing attributes have been deprecated, so why not input.size?


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:

HTML: why isn't the input field SIZE deprecated? we have style="width:xx"!

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:

HTML: why isn't the input field SIZE deprecated? we have style="width:xx"!

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).


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消