图像的DIV中垂直对齐图像、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....

我想设置图像的垂直对齐方式的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>
阅读全文

相关推荐

最新文章