小程序input的placeholder不垂直居中的问题解决

input的placeholder不垂直居中,input设置高度后,使用line-height只能使输入的文字垂直居中,但是placeholder不会居中,反而会偏上。

  1. 首先placeholder样式自定义

有两种方法,第一种行内样式:

<input type="text" placeholder="姓名" placeholder-style="font-size:28rpx;color:#999999;" />

第二种加类名:
给input加上placeholder-class属性,然后给该属性 设置一个类名,在style中设置样式。

<input  type="text"  placeholder="地址" placeholder-class="address"/>
 <style>
 	.address{
      
      
		color: red;
	}
 </style>

placeholder的字体颜色都能改变,但是仍然不会在input框里垂直居中,一直偏上,查了很多方法都不管用,比如:

在这里插入图片描述

比如:

在这里插入图片描述
能垂直居中是能,但是input框变得没有内边距了,很不好看。

  1. 最后找到解决办法了:

在placeholder上增加pandding-top,把提示文字顶下来

参考:IOS下input的placeholder不垂直居中的问题

猜你喜欢

转载自blog.csdn.net/qq_43437571/article/details/132511830