<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>任意盒子居中display:table</title>
<style type="text/css">
*{
margin:0;
padding:0;
}
html,body{
height:100%;
}
.element{
height:100%;
width: 100%;
background-color:blue;
text-align: center;
display:table;
}
.element .img{
display:table-cell;
vertical-align:middle;
}
</style>
</head>
<body>
<div class="element">
<div class="img">
<img src="1.jpg" alt="" />
</div>
</div>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>任意盒子居中display:table</title>
<style type="text/css">
*{
margin:0;
padding:0;
}
html,body{
height:100%;
}
.element{
height:100%;
width: 100%;
background-color:blue;
text-align: center;
display:table;
}
.element .img{
display:table-cell;
vertical-align:middle;
}
</style>
</head>
<body>
<div class="element">
<div class="img">
<img src="1.jpg" alt="" />
</div>
</div>
</body>
</html>