You can make use of justify-content:center
. justify-content is used to align items horizontally
while align-items is used for aligning them vertically.
.navbar {
width: 100%;
height: 64px;
background: #0d1717;
display: flex;
align-items: center;
justify-content: center;
}
.navbar .title {
color: #fff;
font-size: 32px;
font-family: Fairview;
color: #fcfcfc;
}
<header class="navbar">
<div class="navbar-nav">
</div>
<span class="title">Summary</span>
</header>
Using margin:auto on the child element to align horizontally:
.navbar {
width: 100%;
height: 64px;
background: #0d1717;
display: flex;
align-items: center;
}
.navbar .title {
color: #fff;
font-size: 32px;
font-family: Fairview;
color: #fcfcfc;
margin:0 auto;
}
<header class="navbar">
<div class="navbar-nav">
</div>
<span class="title">Summary</span>
</header>
When another content is present as well in the navbar.
You can make use of absolute and relative position and transform the position of title:
.navbar {
width: 100%;
height: 64px;
background: #0d1717;
display: flex;
align-items: center;
position:relative;
color:white;
}
.navbar .navbar-nav {
width: 360px;
height: 100%;
display: flex;
align-items: center;
justify-content: space-between;
}
.navbar .title {
position:absolute;
color: #fff;
font-size: 32px;
font-family: Fairview;
color: #fcfcfc;
left:50%;
transform:translateX(-50%);
}
<header class="navbar">
<div class="navbar-nav">
</div>
<span class="title">Summary</span>
</header>