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

How do I center an image horizontally within a div?

这是代码。我不知道如何使图像在 div 内水平居中。提前致谢!

.first {
    height: 100%;
}
.first img{
    width: 100px;
    height: 100px;
    position: relative;
    margin: 0 auto;
}
.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
}