IE6/IE7通过定位实现,IE8及以上、firefox、chrome等通过display:table-cell实现。
结构:
<div class="box">
<div><span>dddfff <br />dssdsd <br />ssd</span></div>
</div>
样式:
.box{width:200px;height:200px;background-color:#aaa;display:table;position:relative;}
.box div{display:table-cell;vertical-align:middle;}
*html .box div{position:absolute;top:50%;}
*html .box span{position:relative;top:-50%;}
*:first-child+html .box div{position:absolute;top:50%;}
*:first-child+html .box span{position:relative;top:-50%;}