Size attribute for an input field not being honored

前端 未结 4 1708
不思量自难忘°
不思量自难忘° 2020-12-28 14:28

Taken directly from W3Schools:

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

For

4条回答
  •  心在旅途
    2020-12-28 15:08

    You can't take that literally, as that is not possible.

    The width of the element is based on the size attribute and the font size used, but it won't fit that number of characters exactly, because that is not possible.

    All characters doesn't have the same width, so the characters llll will easily fit in an input with size="4", but the characters mmmm won't.

    Also, there is some extra space added, so an input with size="2" will not be twice as wide as an input with size="1".

    What's used as an average character width might depend on the browser. I tested in Firefox, and I haven't found any character that matches exactly, but the character * matches that average width pretty well.

提交回复
热议问题