Center image using text-align center?

后端 未结 24 1631
终归单人心
终归单人心 2020-11-21 17:53

Is the property text-align: center; a good way to center an image using CSS?

img {
    text-align: center;
}
24条回答
  •  一向
    一向 (楼主)
    2020-11-21 18:44

    I came across this post, and it worked for me:

    img {
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      margin: auto;
    }

    (Vertical and horizontal alignment)

提交回复
热议问题