Image centering in div

This question already has an answer here:

  • How to make an image center (vertically & horizontally) inside a bigger div 36 answers

  • Two simple options:

  • add margin:0 auto to the element that you want to be centered
  • add: display: flex; justify-content: center; align-items: center; display: flex; justify-content: center; align-items: center; to the parent/wrapper element
  • If the first one doesn't work, the second option definitely should. How it works:

    justify-content defines where flex items will align according to the main axis (horizontally in our case).

    align-items does the same with the axis perpendicular to the main one (vertically in our case).

    链接地址: http://www.djcxy.com/p/75764.html

    上一篇: 将图像集中在一个部分中

    下一篇: 图像以div为中心