CSS IE8 中不正确的垂直对齐
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3893256/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Incorrect vertical alignment in IE8
提问by JMan
The default text in my search box looks fine in Chrome, FF, and Safari (vertical-align: middle).
我的搜索框中的默认文本在 Chrome、FF 和 Safari 中看起来不错(垂直对齐:中间)。
However, the default text rises to the top of the search box in IE 8.
但是,默认文本会上升到 IE 8 中搜索框的顶部。
Is there a workaround for IE? Thanks for your help.
IE 有解决方法吗?谢谢你的帮助。
HTML:
HTML:
<input type="text" class="text" value="Search" title="Search" />
CSS:
CSS:
.text {
height: 47px;
font-size: 18px;
margin: 0;
padding: 0 5px 0 45px;
}
回答by Stuart Burrows
Have you tried setting the line height to match the height of the text box? The text should automatically appear in the middle of the line
您是否尝试设置行高以匹配文本框的高度?文本应自动出现在行的中间
回答by Sanjeev
Specifying line-height causes the cursor to grow very tall in Chrome , i will suggest to use equal padding from top/bottom to vertically align text in IE8, it will work in Chrome/FF/IE8
指定 line-height 会导致光标在 Chrome 中变得非常高,我建议在 IE8 中使用从顶部/底部相等的填充来垂直对齐文本,它可以在 Chrome/FF/IE8 中工作