Why does display: table-cell behave differently when used on pseudo-elements?
For example, the following elements would be placed side by side:
<div style="display:table-cell">one</div>
<div style="display:table-cell">two</div>
Example: http://jsfiddle.net/tQKzq/
However, when using display: table-cell on a pseudo element, the elements are stacked:
div::after{
content: "two";
display: table-cell;
}
<div style="display:table-cell">one</div>
Example: http://jsfiddle.net/tQKzq/1/
The
::afterpseudo-element is rendered as a child of yourdiv, so instead of populating the same row as thedivcell, it lives in its own anonymous block-level table within thedivcell, on its own line, beneath the text “one”.If your
divis displayed as a table row instead, then the text “one” will be contained within its own anonymous table cell, and the::afterpseudo-element in another cell of its own on the same row: