.demo{width:200px;background:red;height:50px;}
.vam{*position:absolute;*top:50%;}
.va{*position:relative;*top:-50%;}
</style>
</head>
<body>
<div class=”mb10″>
<div class=”wrapper”>
<div class=”vam”>
<div class=”va”>
hellow world<br/>
hellow world<br/>
hellow world
</div>
</div>
</div>
</div>
<div class=”mb10″>
<div class=”wrapper”>
<div class=”vam”>
<img src=”cat.jpg” alt=””/>
</div>
</div>
</div>
<div class=”mb10″>
<div class=”wrapper”>
<div class=”vam”>
<div class=”va demo”></div>
</div>
</div>
</div>
</body>
</html>
利用 hack 技术区别对待 firefox、ie8 和 ie6、ie7,在不支持 display:table-cell 的 ie6 和 ie7 下,通过给父子两层元素分别设置 top:50% 和 top:-50% 来实现居中。这种方法的好处是没有增加额外的标签,但缺点也很明显,一方面它使用了 hack,不利于维护,另一方面,它设置了 position:relative 和 position:absolute,带来了副作用。










