镜像文章:在不确定自身高度的情况下,用 CSS 实现元素垂直居中的3种方法
方法一
<div class="wrap">
<div class="inner">html : 让 inner 水平居中</div>
</div>
<style>
.wrap {
float: left;/* 为了让 wrap 的宽度等于 inner 的宽度 */
position: relative;
left: 50%;
background: blanchedalmond;
}
.inner {
position: relative;
left: -50%;
background: rgba(1,1,1,0.2);
}
</style>
方法二
<div class="box">
<div class="box2">
<a href="#">测试文件</a>
<a href="#">测试文件</a>
<a href="#">测试文件</a>
</div>
</div>
<style>
.box{
text-align:center;
}
.box2{
display:inline-block;
*display:inline;
*zoom:1;
}
</style>