I'm looking to vertically align text in a list item. I'm using display: flex;
and align-items: center;
. But my code contains a strong
tag, which gets interpreted as a separate flex item, and so the spaces on either side get collapsed.
I could hack it with
, but is there a proper way to get my text, with inline elements, to vertically align center?
- I know I could wrap the text in a
<p>
. I'm trying to avoid that. - My text might be long enough to wrap, so
line-height
isn't an option. - Once display: contents; becomes widely supported, that would be my go-to solution here.
li {
display: flex;
align-items: center;
height: 8em;/* just for example */
border: 2px solid red;/* just for example */
}
<ul>
<li>It is <strong>Very important</strong> that this text is vertically centered!</li>
<li>Also <strong>Very important</strong> that there are spaces in the text.</li>
</ul>
. I'm trying to avoid that.` --> you should do this and never ever make text container a flexbox container, what you have is nothing compared to what you will have if you will have more lines. Related: https://stackoverflow.com/a/54903923/8620333
– Temani Afif Nov 12 '19 at 19:19