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

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 13:11:37

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.

Marius

A few things you can try:

  • Set the doctype of the document (<!DOCTYPE html>)
  • Set the input to be display:block or display: inline-block
  • Use a reset stylesheet.

It makes sense because the height of the element is naturally more than what you set it to. input elements are assigned a height which, in this case, should be enough to contain the text of your element but you set it to a smaller amount. To show this, remove your height setting.

I got it working removing the padding of the input button and setting a height around 20. then adjusting the height, padding of the anchor element. I Also set the line-height, font-size and the font-family.

worked on FF,IE,safari and chrome :D

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!