Justified and vertically centered Header Elements

1. Using 'text-align: justify' to evenly spread elements horizontally. 2. Vertically centering content without the help of 'float' or 'position: absolute'. ...both are achieved with the help of pseudo-elements.

by Dini Mer

HTML

<header>
    <div><h1>Super Bad</h1></div>
    <nav>
        <a>First Link</a>
        <a>Second Link</a>
        <a>Third Link</a>
    </nav>
  </header>

CSS

@import url(http://fonts.googleapis.com/css?family=Lato:400,700italic);
body { background: #1abc9c; font-family: 'Lato', sans-serif; text-transform: uppercase; letter-spacing: 1px;}

*, *:before, *:after {
    -webkit-box-sizing: padding-box;
       -moz-box-sizing: padding-box;
            box-sizing: padding-box;
}

header {
    text-align: justify;
    height: 8em;
    padding: 2em 5%;
    background: #2c3e50;
    color: #fff;
}

header::after {
    content: '';
    display: inline-block;
    width: 100%;
}
 
header > div,
header > div::before,
header nav,
header > div h1 {
    display: inline-block;
    vertical-align: middle;
    text-align: left;
}
 
header > div {
    height: 100%;
}
 
header > div::before {
    content: '';
    height: 100%;
}
 
header > div h1 {
    font-size: 3em;
    font-style: italic;
}
 
header nav a {
    padding: 0 0.6em;
    white-space: nowrap;
}
 
header nav a:last-child {
    padding-right: 0;
}

@media screen and (max-width: 720px){
     
    header {
        height: auto;
    }
     
    header > div,
    header > div h1,
    header nav {
        height: auto;
        width: auto;
        display: block;
        text-align: center;
    }
     
}

JavaScript

/*
Source: http://tympanus.net/codrops/2013/07/14/justified-and-vertically-centered-header-elements/
*/