1.父display: table;+子display: table-cell;+vertical-align: middle
设置的代码:
.father{
width: 400px;
height: 400px;
background-color: red;
display: table;
}
.son{
background-color: orange;
display: table-cell;
vertical-align: middle;
}
</style>
<body>
<div class="father">
<div class="son">
<span> 1.父元素使用display: table;和子元素 display: table-cell;
来模拟表格,子元素再使用vertical-align: middle即可实现垂直居中。</span>
</div>
</div>
</body>
设置之后的效果:
2.父 height+ line-height+子display:inline-block+vertical-align: middle+line-height
<style>
.father{