Input type “number” won't resize

后端 未结 7 1552
面向向阳花
面向向阳花 2020-12-13 05:45

Why won\'t my input resize when I change the type to type=\"number\" but it works with type=\"text\"?

EXAMPLE

    Email: &l         


        
相关标签:
7条回答
  • 2020-12-13 06:18

    Incorrect usage.

    Input type number it's made to have selectable value via arrows up and down.

    So basically you are looking for "width" CSS style.

    Input text historically is formatted with monospaced font, so size it's also the width it takes.

    Input number it's new and "size" property has no sense at all*. A typical usage:

    <input type="number" name="quantity" min="1" max="5">
    

    w3c docs

    to fix, add a style:

    <input type="number" name="email" style="width: 7em">
    

    EDIT: if you want a range, you have to set type="range" and not ="number"

    EDIT2: *size is not an allowed value (so, no sense). Check out official W3C specifications

    Note: The size attribute works with the following input types: text, search, tel, url, email, and password.

    Tip: To specify the maximum number of characters allowed in the element, use the maxlength attribute.

    0 讨论(0)
提交回复
热议问题