See this fiddle. When I take out the text, the spans line up next to each other nicely. When I add text to one, it appears lower in the page.
<div>
<span id="first">
</span>
<span id="second">
Text
</span>
</div>
span#first {
display:inline-block;
width: 100px;
height: 100px;
background-color: red;
}
span#second {
display: inline-block;
width: 100px;
height: 100px;
background-color: yellow;
}
The default value of
vertical-alignisbaseline. The CSS spec says that forvertical-align: baselineAn empty block has no baseline, so the bottom of the
spanlines up with the baseline of the parentdiv. The nextspan, since it has text (and therefore a baseline), lines up the text with the baseline of thediv.If you set
vertical-align: topon bothspanelements, they should line up correctly.