Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS Framework Basics What's New in Foundation 5 Off Canvas Navigation

Max Weir
Max Weir
14,963 Points

How would you should the main nav on desktop and then switch to off canvas on smaller screens?

This method displays the off canvas on desktop, I'd like to show the nav as a horizontal list across the bar on desktop then switch to off canvas on small screens.

3 Answers

Max Weir,

You would have to use media queries for that. See this Treehouse series for more in-depth explanation.

In short, using media queries, you can set conditional styles based on screen resolution. The simplest way would be to have two separate navigation elements in your HTML but only show the appropriate one based on screen size. So, you could effectively you would have CSS like this:

/* For desktop/default state */
nav.topbar {
  /* Your normal navigation styles here */
}

nav.offcanvas {
  /* Hide the off canvas navigation */
  display: none;
}


/* For smaller screens, here anything smaller than 720px but you could choose whatever width you want */
@media screen and (max-width: 720px) {

  /* Hide the topbar, show the off canvas nav */
  nav.topbar {
    display: none;
  }
  nav.offcanvas {
    display: block;
  }
}
Max Weir
Max Weir
14,963 Points

Thanks Vishal, was thinking something along these lines. Ideally I'd like to use the same html in both cases but as of current foundation would need 2 versions of the nav like you mentioned.

Silvio Heinze
Silvio Heinze
16,400 Points

You could also do it with the interchange features in Foundation 5. Load the navigation from another file as described here on treehouse. You can then use the normal small,medium,large syntax.

Max Weir
Max Weir
14,963 Points

Love that idea! Just saw a post about this and its definitely a possibility.