1. What the reason to change baseline of inline-block element from baseline of its line box to bottom margin edge?
The baseline of an 'inline-block' is changed to its bottom margin edge when its overflow
property is set to hidden
(full specification here).
As for the reason for this decision, I think since the overflown part is hidden, user agents (browsers) may choose to render that overflown part and not display it, or choose to not render it at all. And when the overflown part is not rendered, user agents have no way to tell the baseline of its last line box, as it is not rendered, where it goes is not known.
If the baseline of 'inline-block' whose overflow
is set to hidden
is still kept as the baseline of its last line box, user agents are forced to render what is hidden to user, which may hinder performance, or at least, put extra restrictions on user agents. What's more, in such case, other inline texts in the same line box are aligned to such a baseline where texts around the overflow-hidden inline-box is hidden, which is kind of stange and not intuitive.
I made a simple demo emulating that inline-block with overflow hidden still has its baseline set to the baseline of its last line box.
var isOverflowHidden = false;
document.querySelector('button').onclick = function() {
document.getElementById('inline-box').style.overflow = isOverflowHidden ? '' : 'hidden';
isOverflowHidden = !isOverflowHidden;
}
html { background: white; }
#inline-box { display: inline-block; height: 18px; }
.overflown { color: white; }
<p><button id="toggle">Toggle 'overflow: hidden;' on 'inline-block'</button></p>
<span>
texts sit
<span id="inline-box">
texts in inline-block <br>
<span class="overflown">
line 2 <br>
line 3
</span>
</span>
on baseline
</span>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…