开发者

Firefox line-height issue with input fields

开发者 https://www.devze.com 2023-01-14 19:16 出处:网络
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

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 ot开发者_高级运维her 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?


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


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.


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.


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.


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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号