Is there a way to vertically center the contents of a flexbox item while using justify-content:stretch;
? The old method of using
display:table-cell;vertical-align:middle;
does not seem to work in this scenario. Is there an alternative solution?
.flex-container {
display:flex;
align-items:center;
justify-content:stretch;
}
.flex-item {
align-self:stretch;
}
<div class="flex-container">
<div class="flex-item">I want to be vertically centered! But I'm not.</div>
</div>
BEFORE YOU RESPOND: Please note that my goal is to center the CONTENTS of the flex-item. When using justify-content:stretch
, the height of the item stretches to match the container, but the contents remain at the top (especially in Chrome).
"A picture is worth a thousand words." Image (A) demonstrates the current state, while image (B) shows the desired outcome.