The Foundation Top Bar gives you a great way to display a complex navigation bar on small or large screens.
Build With HTML Classes
The top bar is a pretty complex piece of magical UI goodness, which makes it really difficult to create a mixin from it. We rely on many presentational classes to accomplish the styles and there's a lot happening in the JS. The top bar is hoverable by default but can be changed to a click event by adding a simple data-option="is_hover:false" to the <nav> element. See an example below.
Basic Needs
The top bar has four main elements, three of which are needed for proper functionality: ul.title-area, a ul class="right/left element enclosed in a section class="top-bar-section", and the li.toggle-topbar element that will expand the menu in the mobile layout. You can leave out the li class="name" as long as you include the .toggle-topbar element.
Positioning the Bar
The top bar is built with a single nav element with a class of top-bar. It will take on full-browser width by default. To make the top bar stay fixed as you scroll, wrap it in div class="fixed". If you want your navigation to be set to your grid width, wrap it in div class="contain-to-grid". You may use fixed and contain-to-grid together.
Building the Nav
When building your bar it is good to be aware of how many links you're going to need in it so you can customize your responsive breakpoint accordingly. Build your navigation with ul.left and/or ul.right depending where you want links. To add items, simply include li elements with and anchor inside them for your top-level. To build a dropdown menu, you'll need to add has-dropdown to the li and include ul.dropdown after that anchor. Add a class of active to mark the current page.
Other Elements
To make this navigation nice and flexible, we've included patterns for elements like buttons, inputs and dividers. To create dividers between your navigation, just add an empty li.divider and you'll get some separation. You can use a small Foundation button in the nav, just include has-form as a class for its parent li. You can include two different input types: search and text. To use these, add a class of search to the parent li.
Sticky Top Bar
You may also wrap your top bar in div class="contain-to-grid sticky" and put it anywhere within your markup. When the navigation hits the top of the browser, it will act like the fixed top bar and stick to the top as users continue to scroll. Note: If you are using Scss, you can control the default sticky class by adjusting the $topbar-sticky-class variable. Make sure the JS variable for stickyClass matches whatever class you use in the variable.
<%= code_example '
', :html %>
Clickable Topbar
You can now make the top bar clickable by adding a data-attribute to the nav element. Here's an example: