DIV as display:block
(block level element) has characteristic/behavior to occupy entire page width. So when you assign auto for margin-left and margin-right, it automatically takes up the available space equally on both sides. So the element will be centered based on width of its parent element.
When you change the display property of a DIV to display:inline-block
. It takes up the best of both worlds (block & inline) i.e., You can use a definitive margins, padding like block elements AND it can follow the normal HTML layout flow like any inline element e.g., span or anchor.
So when you say auto to an inline-block, the default automatic behavior for inline-block is to follow the normal flow of the document (i.e., 0px).
Official definition for auto :
Auto margins
Depending upon the circumstances, provision of an auto value instructs the browser to render a margin according to the value
provided in its own stylesheet. However, when such a margin is applied
to an element with a meaningful width, an auto margin instead causes
all of the available space to be rendered as whitespace.