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 CSS Foundations The Box Model Positioning Properties

Elena Paraschiv
Elena Paraschiv
9,938 Points

Creating Menu with position:fixed . help

Hey guys,

I am taking advantage of the position:fixed that Guil presented , to make a fixed navigation. the problem that I encounter is that the nav does not appear on top of the fixed div.

Here is my code:

<body>

<header>
    <div class="fixed">
        <nav>
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Contact</a></li>
         </ul>
        </nav>

    </div>
    <a href="img/logo.png" > 
        <img src="img/logo.png" >
    </a>
</header>
body{
    background:#be9f23  ;
}
/*********************************************************
Fixed navigation
********************************************************/
.fixed{
    position:fixed;
    width:100%;
    height:4em;
    background:#f2ede4;
    color:black;

}

nav{
    display:inline-block;
    color:#000;
    background:tomato;
}

1 Answer

Gianmarco Mazzoran
Gianmarco Mazzoran
22,076 Points

Hi Elena!

do you mean this results?

style.css
body{
    background: #be9f23;
    margin: 0;
    padding: 0;
}
/*********************************************************
Fixed navigation
********************************************************/
.fixed{
    position:fixed;
    width:100%;
    height:4em;
    background:#f2ede4;
    color:black;
    z-index: 10; /* keep the header in front of other objects */
}

nav{
    color:#000;
    background: tomato; /* amazing color choice! */
}

nav ul {
  list-style: none;
  margin-top: 0;
}

nav ul li {
  display: inline-block;
}