Vertical-align doesn't apply to blocks and isn't inherited, so no point
in ever applying it to a div unless you've changed the div to display:
inline or table-cell.
The second span is vertically aligned with respect to the "strut" of its
container, which has normal font-size.
If you add vertical-align: middle to the _first_ span, then the second
one ends up roughly halfway up it.
The reason this is all so counterintuitive is that both spans are being
aligned to something that you can't see.
The affect of aligning the big span is to move the top edge of the
invisible imaginary inline parent which the second span is aligned
relative to, relative to the containing div. So the second span (which
is positioned relative to that imaginary inline parent) moves on the
screen.
There too the word Hello is vertically aligned within its inline parent,
which since it doesn't have one, is this so called "strut" of the div.
That has normal line-height, so "Hello" doesn't move much.
Yes exactly! It is very confusing.
I will try to explain again.
Vertical-align (on an inline box) aligns it with respect to its inline
parent. The obvious case in which this makes sense is when you nest one
span inside another. The two spans may have different font sizes.
Normally the inner span's baseline lines up with that of the larger one
(its inline parent), but you can move it up and down with
vertical-align. The obvious time you might want to do this is for super
or subscript.
If an inline element doesn't have an inline parent (because its parent
is a block), then it's treated as though it had an inline parent anyway,
with the font-size that applies to the block. That imaginary inline
parent is called the "strut".
In this case, the strut is not particularly tall-- it has font-size:
normal. The first span, the one containing XY, is lined up so that its
middle is at the middle of the strut.
The second span is lined up with its baseline at the strut's baseline.
So why does the second span move up? Because the alignment of the first
span causes the line box top edge to move down relative to the
strut's baseline.
Once both the spans have been lined up with respect to the strut, then a
bounding box is drawn around the whole lot. That's the line box. The
line box sits in the div with its top edge at the top of the div.
The first span is the biggest thing on the line. It's therefore what
determines the height of the line box. If it's vertical-align: baseline,
it pushes the top of the line box up more than it pushes the bottom of
it down. If it's vertical-align: middle, it pushes the top up less and
the bottom down more.
Here are some diagrams:
http://tidraso.co.uk/misc/vertical-align.html