I want to have an inline div within text, so that the div contains two lines of text aligned vertically.
The initial solution:
div.chinese-word {
display: inline-block;
}
div.chinese-word div {
text-align: center;
}
This is a Chinese word <div class="chinese-word"><div>wǒ</div><div>我</div></div> in an inline div
However, it gets broken whenever I put it inside p paragraph. (it might not be the only case).
Invalid!
div.chinese-word {
display: inline-block;
}
div.chinese-word div {
text-align: center;
}
<p>This is a Chinese word <div class="chinese-word"><div>wǒ</div><div>我</div></div> in an inline div</p>
It does not even pass validation. I found out that p must contain inline elements only so I switched to spans. But no matter what styling I use, I can't get the same result.
span.chinese-word {
display: inline-block;
}
span.chinese-word span {
text-align: center;
}
<p>This is a Chinese word <span class="chinese-word"><span>wǒ</span><br/><span>我</span></span> in an inline span</p>
Clearly, the texts in spans are not horizontally centered anymore. (Both lines appear to be left-aligned).
The p element might have its own styling so I don't want to manipulate it and rather need context-independent solution.