Please consider the following HTML code:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>test</title>
<style>
.section {
display: inline-block;
border: 1px dashed blue;
}
.outer {
border: 1px dashed red;
margin: 10px;
}
</style>
</head>
<body>
<div style="height: 500px; width: 200px;" class="section">a
<div style="height: 100px;" class="outer">1A<br />1B</div>
</div>
<div style="height: 500px; width: 200px;" class="section">b
<div style="height: 200px;" class="outer">2</div>
<div style="height: 200px;" class="outer">3<br />4<br />5</div>
</div>
</body>
</html>
Since both divs with class ".section" are the same height, and are inline-blocks, I would expect them to be both vertically aligned. However, the first of these divs is pushed down, so that the text "1B" is aligned with the text line "5" from the other section. Adding or removing lines in either div has a direct impact on the vertical position of my first section.
I don't see the logic of this, and I can't find the answer in the official CSS3 documentation either. Yet, it does not seem to be a bug, as it's identical in Chrome 8, Safari 5, Opera 9.5 and Firefox 4 beta ... didn't try IE, since it's not a reference anyway.
I'm looking for a rational explanation for this phenomenon. Of course there are several workarounds (e.g. changing inline-block to inline-table fixes the problem, or I could use normal floating blocks, etc ...). However I'm trying to comprehend this behaviour.
Hopefully there is someone wiser than myself out there who can explain this.
Live example here.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…