close
例1
<style>
#parent
{
display:table;
border:solid 1px black;
height:80px;
}
#child{
display:table-cell;
vertical-align:middle;
}
</style>
<div id="parent">
<div id="child">垂直居中</div>
</div>
例2,DIV垂直居中
<style>
.parent{
width:200px;
height:150px;
border:1px solid #000;
}
.child{
position: relative;
top:50%;
margin:0 auto;
transform:translateY(-50%);
background:#095;
}
</style>
<body>
<div class="parent">
<div class="child">垂直居中</div>
</div>
全站熱搜