Note that there are some explanatory texts on larger screens.

plurals
  1. POCSS: unexpected vertical position of "inline-block" elements
    primarykey
    data
    text
    <p>Please consider the following HTML code:</p> <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html;charset=utf-8"&gt; &lt;title&gt;test&lt;/title&gt; &lt;style&gt; .section { display: inline-block; border: 1px dashed blue; } .outer { border: 1px dashed red; margin: 10px; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div style="height: 500px; width: 200px;" class="section"&gt;a &lt;div style="height: 100px;" class="outer"&gt;1A&lt;br /&gt;1B&lt;/div&gt; &lt;/div&gt; &lt;div style="height: 500px; width: 200px;" class="section"&gt;b &lt;div style="height: 200px;" class="outer"&gt;2&lt;/div&gt; &lt;div style="height: 200px;" class="outer"&gt;3&lt;br /&gt;4&lt;br /&gt;5&lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>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.</p> <p>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. </p> <p>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.</p> <p>Hopefully there is someone wiser than myself out there who can explain this.</p> <p>Live example <a href="http://jsfiddle.net/Kyle_Sevenoaks/RUerA/" rel="noreferrer">here</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload