Center image using text-align center?

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

    I discovered that if I have an image and some text inside a div, then I can use text-align:center to align the text and the image in one swoop.

    HTML:

        

    Picture #1

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Temporibus sapiente fuga, quia?

    CSS:

    .picture-group {
      border: 1px solid black;
      width: 25%;
      float: left;
      height: 300px;
      #overflow:scroll;
      padding: 5px;
      text-align:center;
    }
    

    CodePen: https://codepen.io/artforlife/pen/MoBzrL?editors=1100

提交回复
热议问题