Input width with type submit less than input with type text

后端 未结 2 999
谎友^
谎友^ 2021-01-19 03:52

I don\'t understand why input width with type submit less than input with type text. Could you help me with it?

HTML:

相关标签:
2条回答
  • 2021-01-19 04:08

    The two input types have their own default styling (margin, padding etc). In order to include these in the width calculation to normalize the set width, use box-sizing:border-box;

    Change your CSS to:

    input {
        width: 200px;
        box-sizing:border-box;
    }
    

    More on box-sizing from MDN

    The box-sizing CSS property is used to alter the default CSS box model used to calculate widths and heights of elements.

    0 讨论(0)
  • 2021-01-19 04:10

    Demo

    The box model being used is different for both the inputs, you can make the box models the same by specifying them box-sizing

    css

    input {
        width: 200px;
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;
    }
    
    0 讨论(0)
提交回复
热议问题