Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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;
}