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

JavaScript

Sticky Navigation

Here is my sticky navigation http://codepen.io/brayk2/pen/ravhG/

Can someone explain why it doesn't work?

Hi Kirk,

For whatever it's worth I did not see any element in your html with the class of nav-scrolled.

Jeff

There isn't supposed to be it is just a class that is added to the nav element in the jquery

Perhaps this would help: Forum Tip: "Page Pocket" Scroll Effect

1 Answer

Kirk Kness , You need to move

.nav, .para {
    position: relative;
}

above where you define the css for .nav-scrolled.

what's a happening is that your nav is having nav-scrolled added to it, however it also still has the .nav class. Which is fine except you tell nav-scrolled to be position: fixed and then right below that still tell .nav to be relative. Since the .nav is lower, it wins and the element is positioned relative.

Here's how it should look:

.nav, .para {
    position: relative;
}

.nav-scrolled {
    width: 100%;
    position: fixed;
    top: 0;
}

/** this is where .nav, .para was before **/

//reference video: Forum Tip: Create a Sticky Navigation with CSS and jQuery

Thanks a ton that did the trick!