I am having trouble understanding the default behavior of display: flex
Why does my header
vertically centers its children when I only add display: flex
to it.
I have not added align-items: center;
to the header
.
Is it because I assigned it height: 100px;
?
header {
display: flex;
border: 1px solid black;
height: 100px;
}
header div {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
max-width: 1224px;
margin: 0 auto;
}
nav a:not(:last-child) {
margin-right: 55px;
}
<header>
<div>
<a href="#">Link</a>
<nav>
<a href="#">one</a>
<a href="#">two</a>
<a href="#">three</a>
</nav>
<a href="#">Link</a>
</div>
</header>
I am aware that the div
has display: flex
and align-items: center;
But why does the parent html element header
also need display: flex
for its children to vertically center?