How can I align content in a flexed item?
The title to the top and the "rest"-content centred?
jsFiddle: https://jsfiddle.net/1wc5kv0d/4/
.row {
display: flex;
}
.col {
margin-left: 20px;
border: 1px solid black;
}
.fixed-width-height {
width: 40px;
height: 40px;
display: inline-block;
background-color: blue;
vertical-align: middle;
}
.inline-wrapper>span {
vertical-align: middle;
}
h3 {
font-size: 1rem;
}
<div class="row">
<div class="col">
<h3>
title
</h3>
<div class="should-center">
<span>Lorem Ispum</span>
<span>Icon</span>
</div>
</div>
<div class="col">
<h3>
another title
</h3>
<div class="should-center">
<div class="inline-wrapper">
<div class="fixed-width-height">
<span>Name</span>
</div>
</div>
</div>
</div>
</div>
How can I achieve that the titles (h3’s) stay on top and the content below should be equally centred. (Lorem Ipsum should be on the same height as "Name")
Should be (Forget that black stroke, photoshop struggled):
2
Answers
use this:
The
.should-center
and.col
arn’t flex items.If you’d make the
.should-center
display: flex
, you can useflex-grow: 1
to let it grow to100%
, then usealign-items: center;
to vertically align them.I’ve also added
display: flex;
to the.col
to ensure all the childs are able to grow the the parent