samrudhi sharma
samrudhi sharma

Reputation: 29

Image visible over fixed header

I have created a header with position: fixed and below that I added a logo using image replacement. However, when I scroll down, the image moves over the header rather than under it.

How can I get the fixed header to always be on top (i.e. force the images to move under it)?

Here is part of my code:

HTML

<header>
    <nav>
        <ul>
            <li>Home</li>
            <li>About</li>
            <li>Work</li>
        </ul>
    </nav>
</header>

<div class="banner">
    <h1><img src="imgs\logo.png" />Jackle</h1>
    <h3>We design and create.</h3>
</div>

<img src="" class="representationBannerPic">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veritatis recusandae ullam dolores sint eligendi voluptatibus incidunt esse vero totam aspernatur. Iste quae molestias sed enim corrupti rerum nam culpa asperiores.</p>

CSS

header
{
    background-color: black;
    width: 100%;
    height: 47px;
    color: white;
    position: fixed;
}
.banner
{
    background-color: #3b97b1;
    background-color: #5fa1b4;
    height: 247px;
    width: 100%;
}
.banner h1 
{
    text-align: center;
    position: relative;
    top: 100px;
    text-indent: -9999px;
}
.banner h1 img
{
   position: absolute;
   top: 50%;
   left: 50%;
   width: 200px;
   height: 60px;
   margin-top: -30px; /* Half the height */
   margin-left: -100px; /* Half the width */
   padding-top: 20px;
}

If you need to see more, the entire code can be found here.

Upvotes: 2

Views: 19117

Answers (2)

Tom
Tom

Reputation: 3520

Add the following rule to your header style:

header
{
    /* ... */
    z-index: 99;
}


The z-index property specifies the overlay order of positioned elements. Elements with a greater z-index will therefore always be infront of elements with a lower z-index. Setting the z-index to a value greater than (or even equal to) 0 sets that element to be on top of non-positioned elements with no z-index specified. You could always set it to a value lower than 99, but, it is common practice to avoid potential clashes with other positioned elements.

Upvotes: 17

Hassaan
Hassaan

Reputation: 326

header {
    z-index: 1;
}

.banner {
    position: relative;
    z-index: 0;
}

It works in every browser with no side effect.

Upvotes: 0

Related Questions