Firefox line-height issue with input fields
Asked Answered
S

7

32

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?

Sruti answered 6/9, 2010 at 9:55 Comment(5)
Oh, I need to mention that I only confirmed it with 16px font size. It most probably varies with different font sizes. Probably.Sruti
Ok, found an answer: cssnewbie.com/input-button-line-height-bugSruti
this is also related #7230068Doris
"It most probably varies with different font sizes." It also varies across browsers AND typefaces unfortunately. meyerweb.com/eric/thoughts/2008/05/06/line-height-abnormalNerve
Anyone running into this problem should voice their support of these two bug reports bugzilla.mozilla.org/show_bug.cgi?id=349259 bugzilla.mozilla.org/show_bug.cgi?id=697451Nerve
P
23

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

Proximate answered 3/9, 2012 at 14:53 Comment(3)
Good find. Saved me another head bang to the wall :) +1Torrie
my god... this will never be fixed.Coal
perfect sample of '!important is anti-pattern in css'Mors
C
5

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.

Coal answered 23/10, 2013 at 11:3 Comment(0)
L
4

As far as I know from experience the line-height on input won't change unless you change the font-size - than the line-height will change to be the same as font-size + 4px (2 top 2 bot i guess).

In case this bothers you with styling, you can use the top and bottom padding to achieve a fake bigger line-height effect.

Levileviable answered 6/9, 2010 at 10:25 Comment(3)
See, that's the thing - when you don't specify the line-height and just play with padding, it will look completely different on other browsers. At least in webkit browsers on OSX.Sruti
Yup, it can mess around alot. I wouldn't suggest styling input fields at all and leave the default behaviour (also you can hardly confuse the user leaving it on default) and also not worth wasting precious time if the money benefit won't be much from adding this feature.Levileviable
Another approach you can take is to remove all the styling from the input and make it transparent and than style it's looks with a wrapping div and backroundg image- I often use this technique on graphic intensive designs and users will hardly notice the line-height at all.Levileviable
P
3

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.

Poaceous answered 29/3, 2012 at 16:55 Comment(0)
R
1

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.

Rapscallion answered 10/3, 2016 at 0:32 Comment(0)
H
0

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

Herzberg answered 9/10, 2011 at 11:23 Comment(2)
vertical-align: middle; isn't applied in Chrome 30 (OS X) when using this technique.Coal
Best way to avoid it use 'padding', it'll work on all browsers including IE 7-8-9, FF, Chrome, Safari on Windows 7-8Herzberg
S
0

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...

Saturniid answered 17/3, 2014 at 16:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.