DIV里的内容垂直居中

<style type="text/css">
.square{
400px;
height:500px;
border:1px solid #CCC;
text-align:center;
}

.photo{
margin-top:expression((parentElement.parentElement.offsetHeight-this.offsetHeight)/2);
}
</style>

<div class="square">

<a href="#"><img src="http://www.baidu.com/img/logo-yy.gif" border="0" class="photo"></a>

<div>
或者
1 字体垂直居中可以用css定义div的字体的行高同DIV一样高,这样就垂直居中了。
比如:
div{line-height: 20px;height: 20px;}

2 图片不是可以用这个
<img align="absmiddle" src="图片路径" />

原文地址:https://www.cnblogs.com/trendline/p/379688.html