Width of input type=text element

前端 未结 4 929
名媛妹妹
名媛妹妹 2020-12-31 04:00

How come when I do this:


相关标签:
4条回答
  • 2020-12-31 04:09

    I think you are forgetting about the border. Having a one-pixel-wide border on the Div will take away two pixels of total length. Therefore it will appear as though the div is two pixels shorter than it actually is.

    0 讨论(0)
  • 2020-12-31 04:12

    The visible width of an element is width + padding + border + outline, so it seems that you are forgetting about the border on the input element. That is, to say, that the default border width for an input element on most (some?) browsers is actually calculated as 2px, not one. Hence your input is appearing as 2px wider. Try explicitly setting the border-width on the input, or making your div wider.

    0 讨论(0)
  • 2020-12-31 04:31

    I believe that is just how the browser renders their standard input. If you set a border on the input:

    <input type="text" style="width: 10px; padding: 2px; border: 1px solid black"/>
    <div style="width: 10px; border: solid 1px black; padding: 2px"> </div>
    

    Then both are the same width, at least in FF.

    0 讨论(0)
  • 2020-12-31 04:32

    input width is 10 + 2 times 1 px for border

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