To vertically center the text node, you can wrap it with a span
element and then apply the following CSS properties: set the display of .child2
to flex
, and add align-self: center
to the child span
element.
See Updated Example Here
.child2 {
border-left: 1px black solid;
align-self: stretch;
display: flex;
}
.child2 > span {
align-self: center;
}
.container {
display: flex;
justify-content: space-between;
align-items: center;
background-color: yellow;
}
.child1 {
background-color: green;
}
.child2 {
border-left: 1px black solid;
align-self: stretch;
display: flex;
}
.child2 > span {
align-self: center;
}
<div class="container">
<div class="child1">
<h1>Text</h1>
</div>
<div class="child2">
<span>the text that should be centered vertically</span>
</div>
</div>