日期:2014-05-17  浏览次数:20620 次

当<input>的输入框有个较高的高度时,如何使<input>的输入框内容在火狐浏览器实现垂直居中?
一般过高的文本框,字是在文本框内靠顶边对齐的。用了line-height之后可以实现在ie6/ie7下的输入内容垂直居中,但在firefox下没用,请问可否用css令其在firefox下垂直居中对齐??代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<input style="border:1px solid #999; padding:0; margin:0; height:38px; line-height:38px;" type="text"/>
</body>
</html>

------解决方案--------------------
<input style="font-size:12px;border:1px solid #999; padding:10px 3px; margin:0; height:12px;line-height:12px;" type="text"/> 

用padding;测试ie6/7/FF下高度都是34px;

注明:

因ie和FF的光标高度不同,
所以必须设置line-height;
否则ie中的padding-bottom会少2px,被光标占距;

又因字号为12px,但是实际只占11px;
所以在ie中padding-bottom会多1px;
FF中却是padding-top多1px;

如果要求不这个精确的话,是可以使用的;