css - IE 中的输入字段未垂直对齐

标签 css forms internet-explorer

这个问题让我整个上午都快发疯了。我一直在尝试让我的输入字段具有自定义背景,以便在 IE 中正确对齐。我读到其他问题说 line-height 会解决它,但这并没有奏效。

它在 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 及更低版本中垂直居中的任何想法?

最佳答案

这应该很容易修复。 line-height 属性很重要,但当您使用速记字体属性时,它似乎在 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 为你(添加边框只是为了显示它是如何对齐的)。

关于css - IE 中的输入字段未垂直对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10094596/

相关文章:

c# - BackGroundworker 取消不适用于 wbadmin.exe

html - 当最后一个单词后跟一个连字符时,对齐单行会在 IE 中的最后一个单词之前换行

internet-explorer - 防止使用 Internet Explorer 查看页面

html - 如何在 window phone 8 上禁用缩放

jquery 显示隐藏使用相同的类

javascript - 如何在 JS 中旋转图像后更改图像 css?

php - 表单不提交大量数据

c# - Html.DropDownList - 如何添加额外的 <option> 到列表

javascript - 如何在用户浏览此 Jquery slider 时更改 Span 元素的文本?

javascript - IE 中的 PrtScn 按钮的行为与使用 java 脚本的其他浏览器不同