Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@matthewbeta
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewbeta/3a9117141b161beb0c9c to your computer and use it in GitHub Desktop.
Save matthewbeta/3a9117141b161beb0c9c to your computer and use it in GitHub Desktop.
flexible, vertically centered navigation
$color-nav-bg: grey
$color-nav-bg-active
$stretch: -100px; // taller/wider than your links would ever need to stretch
// 1. Set the nav ul to be table
.nav-list {
display: table;
width: 100%;
}
// 2. Set the nav items to be table-cell
.nav-item {
display: table-cell;
vertical-align: center;
width: 1%; // seems to be required?
overflow: hidden;
}
// 3. Set the links
.nav-link {
position: relative;
z-index: 1; // Set it above the pseudo element bg
display: block;
text-align: center;
background-color: $color-nav-bg;
&:after {
content: '';
position: absolute;
z-index: -1; //set below the nav
// 4. stretch the pseudo over the link
top: $stretch;
bottom: $stretch;
left: $stretch;
right: $stretch;
}
&:hover,
&:focus,
&:active {
background-color: $color-nav-bg-active;
&:after {
background-color: $color-nav-bg-active;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment