如何在div中水平居中图像?

时间:2015-05-05 16:26:19

标签: alignment center

这是代码。我无法弄清楚如何使图像在div内水平居中。提前谢谢!

.first {
    height: 100%;
}
.first img{
    width: 100px;
    height: 100px;
    position: relative;
    margin: 0 auto;
}

1 个答案:

答案 0 :(得分:0)

.first {
    height: 100%;
    text-align: center;
}
.first img{
    width: 100px;
    height: 100px;
    position: relative;
    display: inline-block; // this line is only required if your img is not already using display: inline-block
}