简体   繁体   中英

How do I vertically center the text in an input element?

I'm trying to implement a custom design for an input element, which requires me to use the font Akko Pro Light. However, when I do so, the text strangely aligns vertically to the top of the line. This is true for the placeholder text as well as any text I actually write into the element.

文本对齐不正确的输入元素

While testing, other fonts do not produce the same problem.

try using justify-content: center; in css along with text-align: center; unfortunately without seeing the code it is hard to know what you are doing to find what is happening

Make a padding to create a space arround and line-height . Awoid non-standard fonts, it reduces the permonance of your site.

 #field1 { line-height: 30px; padding: 10px; }
 field: <input type="text" value="field1" id="field1" /><br />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM