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

Fixed navigation bar under a header section

Hi all,

i want a navigation bar for a single page website which is positioned under my header section. I want that, if i scroll down, my navigation will be fixed at the top of my browser window. But it should only be fixed if i scroll down. How could i handle this?

Thanks!:)

Wayne Priestley
Wayne Priestley
19,579 Points

Hi Norman, I'm just curious as to why you want a navbar for a single page site? Is it a very long page and you wish to be able to jump from section to section?

Giving the nav element position: fixed; in your CSS should do it.

4 Answers

Mark Josephsen
Mark Josephsen
8,803 Points

You could do it like this:

<div class="footer">
  <!-- footer content here -->
</div>
.footer {
  position: fixed;
  bottom: 0;
}
Logan R
Logan R
22,989 Points

I have never personally done this, but I do know you need to use JavaScript or JQuery to accomplish this.

This might help you out with your problem: http://stackoverflow.com/a/6981076

Cool, that's the solution! Thanks!! :) It's really cool and i will try it next week at work:)

Mark Josephsen
Mark Josephsen
8,803 Points

Hooray! If you don't mind, could you click "Best Answer" for me? It's worth a few points...

Thanks!

Yes, it's a large site. That's because I need a navbar :)