Firefox line-height issue with input fields

2019-01-23 01:30发布

I have realized the problem before but I guess it didn't matter as much then as it did now.

What I discovered is that Firefox has a default line-height value of 1.2 for input fields which can not be changed. At least in OSX, don't have Windows so I can't confirm it there.

I did some experimenting and testing and there's just no way to change the default line-height value of Firefox. All the other browsers (ok, I just tried with Chrome and Safari) obey my value perfectly fine but not Firefox.

Has anyone ever noticed this and if yes, have you found a solution to overcome this?

标签: css firefox
7条回答
Root(大扎)
2楼-- · 2019-01-23 01:51

Use Height instead of Line-Height. This works for me in almost all browser on Windows7, but I have not tested it on OSX.

查看更多
Luminary・发光体
3楼-- · 2019-01-23 02:03

Line-height cannot be applied to replaced inline elements such as buttons and inputs. This is the correct behavior relative to the Spec.

See https://developer.mozilla.org/en/docs/Web/CSS/line-height for more details.

查看更多
Explosion°爆炸
4楼-- · 2019-01-23 02:07

If your input and submit button are side by side, with the button down about 1px lower then the input (looks like your background image is off), a simple:

display:inline-block;
vertical-align: top;

on the button lines it up perfectly in FF & IE.

查看更多
Rolldiameter
5楼-- · 2019-01-23 02:09

I always style my buttons against anchors, buttons, labels, and submits to ensure that regardless of which element used, the outcome looks exactly the same.

Since Firefox insists on using !important to declare line-height, the only way I can calmly overcome this issue is to force all other vendors to use line-height: normal for buttons, and then use padding to vertically center the text:


/**
 * Consistently style buttons on anchors, buttons, labels, and submits
 */
.btn {
    .
    .
    .
    height: auto;        // ensure heights on inputs do not affect submit buttons
    line-height: normal; // all browsers use FF's ever unchanging value
    padding: .5em 1em;   // vertically center the text in the button
    .
    .
    .
}

This works similarly for inputs.

查看更多
欢心
6楼-- · 2019-01-23 02:12

Unfortunatelly the line-height is set to !important in the Firefox base css ... http://hg.mozilla.org/mozilla-central/rev/b97aef275b5e

查看更多
走好不送
7楼-- · 2019-01-23 02:13

Just give the wrapping form element the desired line height and at least all input fields of type="text" in Firefox will take that same line height. Submit buttons seem to behave differently though...

查看更多
登录 后发表回答