实现水平+垂直居中,也就是在中央:(1)单行行内元素:父元素设置:text-align:center,display:table-cell;vertical-align:middle,在这里,图片,文字,都是一样的操作
<!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>Document</title>
<style>
.box {
background-color: #ccc;
width:500px;
height: 500px;
display:table-cell;
text-align: center;
vertical-align: middle;
}
img{width:50px;
height: 50px;}
</style>
</head>
<body>
<div class="box">
<img src="5.jpg" alt="">
</div>
</body>
</html>
更多信息见文章 https://blog.csdn.net/qq_35788269/article/details/80691114