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 navbar

Hi guys, I want the navigation bar to be fixed so when I can scroll down I can still see it. But it looks like the position: fixed; rule is not working...

    <header>
      <div id="heading">
        <div class="extra-border">
          <img src="img/logo.jpg" class="logo">
          <nav class="main-nav">
            <ul>
              <li>Inicio</li>
              <li>Contacto</li>
            </ul>
          </nav>
        </div>
      </div>
    </header>
#heading {
  z-index: 1;
  border-bottom-width: 5px;
  border-bottom-style: solid;
  border-bottom-color: #fff;
  box-shadow: 0px 5px 11px 2px #474a5b;
  width: 100%;
  position: relative;
}

3 Answers

You can use position: fixed so it stays on top even when scrolling.

Nop, its not working correctly, when I use the fixed value it pushed down my cover like 600px and if I scroll later the other images of my main content or cover overlap my main nav (#heading)

With the z-index you can prevent your images or divs to overlap your nav bar. The 600px diffrence is weird do you have a rule which targets the nav element ? Because when you set your position to fix you can assign the distances with top bottom and so on. By the way there is a header tag. For both the fixed and the header tag(http://cssreset.com/creating-fixed-headers-with-css/) :)