你的位置:首页 > 网页设计

[网页设计]如何垂直居中一个img?


<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="Author" content="胡超">
<title>super胡</title>
<style>
#a1{
display:table-cell;
text-align:center;
vertical-align:middle;

}
#a2{
display:table;
width:300px;
height:300px;
border:1px solid red;



}
</style>
</head>
<body>
<div id="a2">
<div id="a1">
<img src="7v/u=2787330296,1499357788&fm=21&gp=0.jpg"/>
</div>
</div>
</body>
</html>

 //<img>的容器设置如下

2 {

3     display:table-cell;

4     text-align:center;

5     vertical-align:middle;

6 }