Why centering with margin 0 auto works with display:block but does not work with display:inline-block ?

My understanding is as follows (though I am happy to be corrected).

  • Inline elements do not have a width property, and so the “auto” cannot be calculated.
  • Block elements have a width property, so the width of the “auto” can be calculated.
  • Inline-block elements have an outside which acts inline, but an inside which acts like a block. As such, the width set acts more like the width of a word in an inline element.

Leave a Comment