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.


Elvis Reinis Zeltītis
Elvis Reinis Zeltītis
1,925 Points

Image hiding behind background


So im trying to make a website to see how far will I be able to get, and in middle of the way I encountered a problem. The problem is when im adding an image inside or outsive my navigation div, the image appears under background-color. Have tried a few things, none of them worked sadly.

HTML file

<!doctype html>
        <link href="styles/main.css" rel="stylesheet"/>
        <div class='nav'>
            <img src="img/logo.png">
                <li><a href='#'>Home</a></li>
                <li><a href='#'>About</a></li>
                <li><a href='#'>Contacts</a></li>

    <script src="scripts/main.js"></script>

CSS file

/***** Body *****/

body {
    margin: 0;

/***** Header *****/
#logo {


.nav ul {
    list-style-type: none;
    margin: 0;
    padding: 150px 0 0 0;
    width: 100px;
    position: fixed;
    top: 0;
    bottom: 0;

    background-color: #f1f1f1;

.nav ul li a {
    display: block;
    color: #000;
    padding: 12px 0 12px 20px;
    text-decoration: none; /* Removes default links color and underline */

.nav ul li a:hover {
    background-color: #555;
    color: white;

-- Edit

I've found the solution to this problem so I decided to post it rather than delete it, because it could help someone out!

All I did Was I added z-index to image and set it's position to relative! :) If anyone can explain it more detailed I would me more than happy!

#logo {
    position: relative;
    z-index: 1;

1 Answer

Steven Parker
Steven Parker
216,136 Points

By default, items will be rendered in the order they occur in the document, so later items will be "on top" of earlier ones. Normal document flow prevents overlap, but by using fixed position you placed your ul element over your image.

By assigning a position with z-index, you override the default stacking order and put your image on top.