图像的DIV中垂直对齐 [英] vertical alignment of image inside a div

查看:162
本文介绍了图像的DIV中垂直对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置图像的垂直对齐方式的DIV中。我用的img {垂直对齐:中间} 但它不能正常工作。

I want to set vertical alignment of image inside a div. I use img { vertical-align:middle} but it is not working.

推荐答案

使用的line-height 属性将解决这个问题:

Using the line-height property will solve the problem:

<style> 
.someclass {
  width: 300px;
  height: 300px;
  text-align: center;
  line-height: 300px;
  border: dotted;
}
.someclass img {
  margin: auto;
  vertical-align: middle;
}
</style>
<div class="someclass"> 
  <img src="someimg.jpg" border="0" alt=""> 
</div>

这篇关于图像的DIV中垂直对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆