html - 将图像与文本垂直对齐,包括 ie

标签 html css vertical-alignment

执行此操作的最佳方法是什么?

这是我的 html:

<div id="wrapper">
   <img src="http://i.imgur.com/b8xFk.jpg" /> <span id="text">Twitter</span>
</div>

和我的CSS:

#wrapper{
  background-color:orange;
  height:60px;
  padding: 10px;
}

#wrapper img{
  vertical-align:middle;
}

#wrapper #text{
  line-height:60px; 
}

还有一个 jsfiddle

如您所见,图像低于文本(至少在 Firefox 16 中)。在 ie 中,事情变得更加不稳定。将图像与文本垂直对齐以实现跨浏览器兼容性的最佳做法是什么?

提前致谢。

最佳答案

试试这个:

#wrapper img{
  vertical-align:middle;
  /*New:*/
  padding-bottom:4px;
}

Demo

关于html - 将图像与文本垂直对齐,包括 ie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14227281/

相关文章:

css - 如何将跨度与向右浮动的图像垂直对齐?

jquery水平子菜单在菜单单击时保持打开状态

html - 垂直对齐文本 "boxes"

javascript - 如何将 html 布局文件插入到 div 中?

html - 扩展容器时将 div 右对齐

CSS Columns Bug — 使用 :checked pseudo class 时在移动设备上中断

html - 无法让 div 覆盖另一个包含 Canvas 的 div

css - 垂直对齐 : why it does not work for me?

html - iFrame src 中的 HSTS

javascript - 如何获取 jQuery 生成的单选按钮的值