How to fix margin: auto not centering an image with CSS?

Spread the love

To fix margin: auto not centering an image with CSS, we make the img element a block element.

For instance, we write

img {
  display: block;
  width: auto;
  margin: auto;
}

to make the img element a block element with display: block;.

Leave a Reply

Your email address will not be published. Required fields are marked *