Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Foundation 5 - Evenly-spaced Top Bar nav items

Zurb Foundation's top-bar is extremely useful. It works great as a main navigation for a site/app, and collapses to a mobile-friendly format on smaller devices.

Its one major shortcoming is the ability to make the top-bar full-width with evenly spaced nav items. Is there a way to make the top-bar full-width and the nav items evenly spaced?

Example

If the top-bar has 6 nav items (width varying length titles) and we're using the default width of 1000px for .rows (with 15px gutters) the 6 nav items should evenly space themselves across the 970px top-bar. The first and last nav items should be left and right justified respectively.

As the screen size reduces the nav items should shrink in width to maintain their even spacing until the $topbar-breakpoint causes the top-bar to collapse to the mobile format.

Requirements

  • The solution should be CSS-based.
  • The solution should match Foundation 5's compatibility chart. Namely this means it needs to support IE9+.
  • Beneath the $topbar-breakpoint the top-bar should work as normal.

Here's a jsFiddle with the Foundation 5 resources already loaded.

like image 918
Brett DeWoody Avatar asked Feb 26 '14 21:02

Brett DeWoody


1 Answers

Here is another solution. It is based on flexbox which hasn't been supported by browser for very long and it is still only a candidate recommendation: CSS Flexible Box Layout Module

jsFiddle

If you provide a good fallback, like the original Foundation CSS it can be used.

Update

You could also use this jQuery solution as a fallback as I haven't found any polyfills for flexbox: http://jsfiddle.net/borglinm/x6jvS/14/

.top-bar-section > ul {
    display: -webkit-flex;
    display: -moz-flex;
    display: flex;
    -webkit-flex-direction: row;
    -moz-flex-direction: row;
    flex-direction: row;
}
.top-bar-section > ul > li {
    float: none;
    -webkit-flex: 1;
    -moz-flex: 1;
    flex: 1;
}
.top-bar-section > ul > li > a {
    white-space: nowrap;
    text-overflow: ellipsis;
    text-align: center;
    overflow: hidden;
}
like image 101
Mathias Avatar answered Oct 17 '22 14:10

Mathias