Center image using text-align center?

后端 未结 24 1624
终归单人心
终归单人心 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:35

    You can use text-align: center on the parent and change the img to display: inline-block → it therefore behaves like a text-element and is will be centered if the parent has a width!

    img {
        display: inline-block
    }
    

提交回复
热议问题