Vertically align text within input field of fixed-height without display: table or padding?

后端 未结 16 2392
Happy的楠姐
Happy的楠姐 2020-12-01 01:27

The line-height property usually takes care of vertical alignment, but not with inputs. Is there a way to automatically center text without playing around with padding?

16条回答
  •  醉酒成梦
    2020-12-01 01:59

    If your element is a block element contained/or with display like so:

    display: table-cel
    

    Or, with an fixed line-height, you can set the vertical align like so:

    Vertical-Align: Middle;
    

    It won't work for other cases, but it works fine on these conditions.

提交回复
热议问题