I have a header with an image and navigation links.
For some reason the menu items are not vertically centered.
.header {
position: relative;
margin-top: 70px;
background: red;
height: 40px;
}
.logo {
position: absolute;
top: 50%;
transform: translateY(-50%);
max-width: 150px;
}
.nav {
list-style: none;
float: right;
}
.nav li {
display: inline-block;
}
<div class="header">
<img src="http://placehold.it/200" class="logo" />
<ul class="nav">
<li>Home</li>
<li>Contact</li>
<li>About</li>
</ul>
</div>
Live code: https://jsfiddle.net/f2u97o3m/
I tried to add vertical-align: middle to <ul> and <li> items, But it didn't work.
Why it's not centered and how to center it vertically?