Firefox/Safari setting height as [specified height - padding - border] for input[type=button]

前端 未结 4 2155
南旧
南旧 2021-02-15 03:45

When I use the following CSS:

input[type=button] {
  background-color: white;
  border: 1px solid black;
  font-size: 15px;
  height: 20px;
  padding: 7px;
}
         


        
4条回答
  •  被撕碎了的回忆
    2021-02-15 04:32

    Form elements have traditionally had a width/height that includes their padding/border, because they were originally implemented by browsers as OS-native UI widgets, where CSS had no influence over the decorations.

    To reproduce this behaviour, Firefox and others render some form fields (select, button/input-type-button) with the CSS3 box-sizing style set to border-box, so that the width property reflects the entire rendered area width including the border and padding.

    You can disable this behaviour with:

    select, button {
        box-sizing: content-box;
        -moz-box-sizing: content-box;
        -webkit-box-sizing: content-box;
    }
    

    (or, which is more common for liquid form layouts where you want to use ‘100%’ width, you can set the others to border-box.)

    The -browser prefixed versions have to be there to catch browsers that implemented this before the standardisation process got so far. This will be ineffective on IE6-7, though.

提交回复
热议问题