Method 1
Using position:relative;
and top:50
and transform: translateY(-50%)
you can get it centered, this is so good if you don't know the height of the element, like this:
Support : IE9+ and all other browsers, caniuse.com.
JS Fiddle 1
header {
width: 960px;
height: 90px;
margin: auto;
background-color: #000;
}
.logo {
position:relative;
width: 209px;
height: 54px;
top:50%;
left:0;
transform: translateY(-50%);
background-color: #ced0d8;
}
<header>
<div class="logo"></div>
</header>
Method 2: using .calc()
css function ,if you know the height of the element, like this:
Support : IE9+ and all other browsers, caniuse.com
JS Fiddle 2
header {
width: 960px;
height: 90px;
margin: auto;
background-color: #000;
}
.logo {
position:relative;
width: 209px;
height: 54px;
top:calc(50% - 27px); /* 50% parent height - 27px is half of 54px the height of .logo */
left:0;
background-color: #ced0d8;
}
<header>
<div class="logo"></div>
</header>
Method 3: if you know both elements height, you can manually subtract half the height of the .logo
from half of the height of the parent div, so 90/2 - 54/2 = 18, like this:
Support: All browsers, caniuse.com.
JS Fiddle 3
header {
width: 960px;
height: 90px;
margin: auto;
background-color: #000;
}
.logo {
position:relative;
width: 209px;
height: 54px;
top:18px; /* 90/2 - 54/2 = 18 */
left:0;
background-color: #ced0d8;
}
<header>
<div class="logo"></div>
</header>