2012-04-10 61 views
4

这个问题一直让我疯狂。我一直试图让我的输入字段与自定义背景在IE中正确对齐。我读过其他问题,表示行高将解决它,但那还没有奏效。在IE中不垂直对齐的输入字段

在chorme/safari/etc中看起来很好,但在IE8中,文本被卡在输入区域的顶部。 (Stack不会让我发布图像)。我的CSS是:

#email { 
background: url('BACKGROUND IMAGE') left top no-repeat; 
background-size: 273px 38px; 
width: 273px; 
height: 38px; 
line-height: 38px; 
border: 0; 
margin: 0 0 5px; 
font: bold 12px arial, helvetica, sans-serif; 
color: #777; 
padding:0 8px; 
outline: none; 
float:left; 
} 

和HTML:

<input id="email" type="text" name="email" size="14" value="your email address" onfocus="if(this.value=='your email address') {this.style.color='#333'; this.value='';}" onblur="if(this.value== '') {this.style.color='#808080'; this.value='your email address';}" /> 

如何让我的输入文本垂直中心在IE 8和较低的任何想法?

+0

链接到可用的页面? – Rooster 2012-04-10 19:06:35

回答

6

这应该很容易解决。行高属性很重要,但在使用速记字体属性时,它似乎在IE8中丢失了。尝试将行高添加到速记字体属性,并删除已分别声明的行高。

#email { 
background: url('BACKGROUND IMAGE') left top no-repeat; 
background-size: 273px 38px; 
width: 273px; 
height: 38px; 
border: 0; 
margin: 0 0 5px; 
font: bold 12px/38px arial, helvetica, sans-serif; 
color: #777; 
padding:0 8px; 
outline: none; 
float:left; 
border:1px solid #999; 
} 

这里有一个jsFiddle example你(边框添加只是为了显示它是如何对齐)。

+0

比你这么多,完美的工作! – AndrewO 2012-04-10 20:24:21

+0

很酷,很高兴我能帮上忙。 – j08691 2012-04-10 20:24:46