图片在div里面如何居中

<style type="text/css">
body {
background-color: #ececec;
}

.d1 {
text-align: center;
position: relative;
height: 200px;
}

.d2 {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>
</head>

<body>
<div class="d1">
<span class="d2">
<img width="100px" height="100px" src="../image/api_1.png" alt="">
<p>ssss</p>
</span>
</div>

posted @ 2018-12-27 11:47  飞蚊  阅读(153)  评论(0编辑  收藏  举报