前端之家收集整理的这篇文章主要介绍了
css – 在div内的图像的垂直对齐,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想设置一个div内的图像的垂直对齐.我使用img {vertical-align:middle}
但它不工作.
使用line-height
属性将
解决问题:
- <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>