<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>垂直居中一张图片 多行文本垂直居中</title>
<style>
*{
margin: 0;
padding: 0;
}
img{
width: 100px;
}
.picBox{
width: 1000px;
height: 400px;
background-color: pink;
opacity: .2;
display: table-cell;
text-align: center;
vertical-align: middle;
}
.parent {
display: table;
width: 300px;
height: 300px;
text-align: center;
}
.son {
display: table-cell;
height: 200px;
background-color: yellow;
vertical-align: middle;
}
</style>
</head>
<body>
<div class="picBox">
<img src="images/bgc.jpg" alt="">
</div>
<!-- 多行文字垂直居中 display:table 和display:table-cell联合 -->
<div class="parent">
<p class="son">
table: 指定对象作为块元素级的表格。类同于html标签 inline-table: 指定对象作为内联元素级的表格。类同于html标签 table-cell: 指定对象作为表格单元格。类同于html标签
</p>
</div>
</body>
</html>