Since margin-right: auto
and margin-left: auto
center an element horizontally, I would expect their vertical counterparts to behave in the same way.
Yet I understand this does not happen, as per CSS specs:
10.6.2 Inline replaced elements, block-level replaced elements in normal flow, 'inline-block' replaced elements in normal flow and floating replaced elements
If 'margin-top', or 'margin-bottom' are 'auto', their used value is 0.
Also applies to block elements:
10.6.3 Block-level non-replaced elements in normal flow when 'overflow' computes to 'visible'
This section also applies to block-level non-replaced elements in normal flow when 'overflow' does not compute to 'visible' but has been propagated to the viewport.
If 'margin-top', or 'margin-bottom' are 'auto', their used value is 0.
Now what I would like to know, is the rationale behind this decision/behavior.
What I'm searching for is understanding and conviction. I don't think a vague explanation would do it, yet any contribution is welcome.
As noted above:
For example, this CSS:
and this HTML: