I have the following input element (I deliberately omitted attributes which weren't necessary for the example):
<input type="text" style="display: block; height: 40px; font-size: 14px; line-height: 40px">
In Chrome and Internet Explorer (probably Opera too), any text inside the input will be vertically centred. However, Firefox seems to ignore this declaration. Setting it to display: inline-block;
instead, or using vertical-align: middle;
has no effect in Firefox.
I've also tried setting the top & bottom paddings to 13px
, and the height to 14px
, which (combined with the font-size) will result in an element 40px
tall. This works as expected; except any characters with tails (like g, q, j etc) are cut off at the bottom.
I'm looking for a cross-browser solution for vertically aligning text in an input box with a fixed height. The input element will have its own hover and focus styles, so faking the centring by positioning the element itself vertically in a 40px
tall space is not really an option.
Cheers