0

Input text width?

So I noticed that input texts boxes are slightly larger than everything else. For example, when setting a div to 200 px, and setting an input type="text" to 200 px, the input is always wider. Is there a way around this or am I stuck guessing the width? (which is about 197px but it's not perfect) https://code.sololearn.com/Wfu2gi2sd1cq/?ref=app

15th Jun 2018, 2:09 AM
Daniel Cooper
Daniel Cooper - avatar
3 Antworten
+ 6
Actually the problem isn't the input itself, it's the padding! If any element has padding on it, the total width of the element will be width+padding. (Same goes for margin) They implemented another sizing mechanism to change this behaviour to what you would expect: box-sizing: border-box; Give that to your input and it should work. I actually spam that line everywhere. The default (box-sizing: content-box) is just so bad.
15th Jun 2018, 2:18 AM
Schindlabua
Schindlabua - avatar
+ 4
input { width:200px; box-sizing: border-box; }
15th Jun 2018, 2:18 AM
Calviղ
Calviղ - avatar
0
what about 197.49 px?
15th Jun 2018, 2:18 AM
Hemath Kumar
Hemath Kumar - avatar