Form padding differences in Firefox and Opera/Chrome/IE

前端 未结 5 738
时光取名叫无心
时光取名叫无心 2020-12-09 10:21

I\'m having a problem with the padding in my form on my website. If I\'ve set a height/width to a form element and then adds a padding to it. In all browsers I\'ve tried, ex

5条回答
  •  眼角桃花
    2020-12-09 10:23

    Give the input this CSS:

    box-sizing: border-box;
    

    You can read more about box-sizing on QuirksMode, the W3C spec, and MDN. Here is its browser support. Use the prefixes -moz- or -webkit- if required by your target browsers.


    This answer had previously suggested the value initial, which I had found by using the up/down arrow keys in the Chrome Web Inspector. But it turns out that initial is a CSS keyword, applicable to any property, that represents the initial value of the property – the browser’s default value. initial is less safe than explicitly naming which box model to use. If box-sizing: initial were specified and a browser’s default value for box-sizing changed, the input’s padding could break again.

提交回复
热议问题