<nav role="navigation" class="priority-nav">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Clients</a></li>
<li><a href="#">Contact Us</a></li>
<li><a href="#">Buy Lemons</a></li>
<li><a href="#">Dance Wildly</a></li>
<li><a href="#">Go To Bed</a></li>
<li><a href="#">Donate Millions</a></li>
<li class="overflow-nav">
<span class="overflow-nav-title">
▼
</span>
<ul class="overflow-nav-list"></ul>
</li>
</ul>
</nav>
@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro);
.priority-nav {
background: #f06d06;
height: 40px; // not ideal... do with JS?
> ul {
list-style: none;
> li {
display: inline-block;
position: relative;
&.overflow-nav {
display: none;
}
}
}
a {
text-decoration: none;
color: white;
display: inline-block;
padding: 10px 15px;
}
&.resizing {
overflow: hidden;
}
}
.overflow-nav-list {
background: white;
box-shadow: 0 0 10px rgba(black, 0.35);
position: absolute;
top: 95%; // moves to 100% on hover generally
right: 0;
opacity: 0;
visibility: hidden;
padding: 5px 0;
width: 200px;
color: #222;
a {
color: black;
font-weight: bold;
&:hover,
&:active {
background: #f06d06;
color: white;
}
}
list-style: none;
z-index: 1;
right: -20px;
&.show {
opacity: 1;
visibility: visible;
}
> li > a,
.primary > a {
color: black;
display: block;
}
.primary-last {
margin-right: 0;
}
}
.overflow-nav-title {
cursor: pointer;
text-align: center;
background: white;
color: #222;
border-radius: 50%;
font-size: 10px;
width: 2em;
height: 2em;
line-height: 2.2em;
vertical-align: top;
display: inline-block;
}
.hide {
display: none !important;
}
.show-inline-block {
display: inline-block !important;
}
body {
font-family: 'Source Sans Pro', sans-serif;
}
View Compiled
var PriorityNav = {
// used multiple times, so saving.
menu: $(".priority-nav"),
allNavElements: $(".priority-nav > ul > li:not('.overflow-nav')"),
init: function() {
this.bindUIActions();
this.setupMenu();
},
setupMenu: function() {
// Checking top position of first item (sometimes changes)
var firstPos = $(".priority-nav > ul > li:first").position();
// Empty collection in which to put menu items to move
var wrappedElements = $();
// Used to snag the previous menu item in addition to ones that have wrapped
var first = true;
// Loop through all the nav items...
PriorityNav.allNavElements.each(function(i) {
var el = $(this);
// ...in which to find wrapped elements
var pos = el.position();
if (pos.top !== firstPos.top) {
// If element is wrapped, add it to set
wrappedElements = wrappedElements.add(el);
// Add the previous one too, if first
if (first) {
wrappedElements = wrappedElements.add(PriorityNav.allNavElements.eq(i-1));
first = false;
}
}
});
if (wrappedElements.length) {
// Clone set before altering
var newSet = wrappedElements.clone();
// Hide ones that we're moving
wrappedElements.addClass("hide");
// Add wrapped elements to dropdown
$(".overflow-nav-list").append(newSet);
// Show new menu
$(".overflow-nav").addClass("show-inline-block");
// Make overflow visible again so dropdown can be seen.
$(".priority-nav").css("overflow", "visible");
}
},
tearDown: function() {
$(".overflow-nav-list").empty();
$(".overflow-nav").removeClass("show-inline-block");
PriorityNav.allNavElements.removeClass("hide");
},
bindUIActions: function() {
$(".overflow-nav-title").on("click", function() {
$(".overflow-nav-list").toggleClass("show");
});
$(window)
.resize(function() {
PriorityNav.menu.addClass("resizing");
})
.resize(_.debounce(function() {
PriorityNav.tearDown();
PriorityNav.setupMenu();
PriorityNav.menu.removeClass("resizing");
}, 500));
}
}
PriorityNav.init();
This Pen doesn't use any external CSS resources.