A block container whose children are inline-level establishes an inline formatting context. Its content is broken into line boxes, stacked one per line. Each line box is as tall as needed to hold everything on it, computed like this:
- Give every inline-level box a height. A text inline box is exactly its
line-height: the font's ascent plus descent (its content area), with the difference split as half-leading above and below. Replaced elements (<img>,<canvas>) and inline-blocks use their margin box. - Align them with
vertical-align. The default,baseline, lines a box's baseline up with its parent's.middle,text-top,subor a length shift it relative to the parent;topandbottomalign to the line box itself. - Measure. The line box runs from the highest box top to the lowest box bottom.
Every line also starts with a strut: an invisible, zero-width inline box with the block's own font and line-height. So a line is never shorter than the block's line-height, and the baseline always sits where the block's text would sit.
That explains the classic gap under images. An <img> is inline and sits on the baseline. The strut reserves room for descenders below the baseline, so the block ends a few pixels below the image. The fixes all take the image off the baseline or remove the strut's descent: display: block, vertical-align: top | middle | bottom, or line-height: 0 on the parent.
Two more consequences. Vertical padding and borders on an inline <span> paint but don't affect the line box. And vertical-align only applies to inline-level boxes and table cells: it can't centre a block.