Footer Fixed - Z Index

Asked

Viewed 222 times

-4

I’m making a fixed footer while scrolling on the screen.

But I put z-index: -1 to be under all my contents.

When I do this it overrides the Footer Links.

But if I put z-index:0 it sits over some elements of the page.

And even if I do z-index:1 in the page elements, does not work in my case, because the elements are with transparent background because of the background image of the body. Hence because of this the footer keeps appearing from behind.

How do I fix this problem ?

Follows the code:

    #all{

        margin-bottom: 120px;

    }
    ul{
      border-bottom: 1px solid #ccc;
    }


    ul li{
      display: inline-block;
      padding: 10px
     }

    section{
      background: #ccc;
      padding: 20px 10px; 
      z-index: 1;
    } 

    .footer-contato{
        background: #f1f1f1;
        position: fixed;
        height: 100px;
        bottom: 0;
        width: 100%;
        z-index: -1;
    }
<header>
    <nav>
        <ul>
            <li>home</li>
            <li>informações</li>
            <li>localização</li>
            <li>patrocinadores</li>
        </ul>
    </nav>
</header>
<div id="all">
    <section class="home">
        <h1>Home</h1>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    </section>
    <section class="informacoes">
        <h1>Informações</h1>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    </section>
    <section class="footer-contato">
      <h1> Footer fixed </h1>
    </section>
    <section class="local">
        <h1>Local</h1>
       <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    </section>
    <section class="patrocinadores">
        <h1>Patrocinadores</h1>
       <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    </section>
</div>

  • Good afternoon Deesouza, could you set an example that can be reproduced? In this case, there may be other elements or how html markup and other css rules have been made that affect.

  • Check out this LINK: http://jsfiddle.net/ckvda5L3/ - I know how to use the technique, but it’s a problem when you have LINK. My structure is the same as this one. I used this LINK to help a user.

  • Good afternoon Deesouza, have to publish the page so I inspect the elements?

  • No way. It’s on my localhost.

  • 1

    Good afternoon, it was not me, but I believe that the reason is that it is not very clear how the two specified problems occur, I do not think deserves negative for this, has question much more difficult to understand. I think it’s just getting better. Unfortunately it’s having patience Dee.

  • There is no way to reproduce the problem. I do everything in Laravel, it’s Blade. There is no way to slice the code and put some things here. I keep hoping that others will understand the structure and the problem.

  • Deesouza has to take the page generated in the browser and click Ctrl+U on the keyboard and analyze the source code (I believe that the CSS is automatically minified by Aravel, if it is the 5). So you could have more accuracy. Another idea, it’s not very good and very difficult to reproduce, but could post two pictures (of both problems)?

  • Why did my question receive so many negative votes ?

Show 3 more comments

1 answer

4


Now let’s see if we can understand something:

The estate z-index, determines the "stacking level" of an HTML element. The "stacking level" - Refers to the position of the element on the Z axis (as opposed to the X axis or the Y axis). A value z-index higher than > 0, means that the element will be closer to the top, in stacking order, already a value z-index negative less than < 0, will mean the opposite.
This stacking order occurs perpendicularly to the screen (or display window).

So what happens here?

By giving a z-index negative to footer, it will get lower at the stacking level, just when it lies below the rest of the other elements at the stacking level, it will become impossible to click (as these elements are functioning as a layer that is above the footer).

In short

Or put the footer underneath the content making it non-clickable/visible, or put it on top of the contents to make it clickable. There is no middle ground where you can put the footer underneath the content by assigning a .footer-contato{z-index:-1;} and then bring the links back up to the content by giving a z-index only for links, because the z-index now applied to the elements within the footer, will respect the order of the z-index class - .footer-contato and not the document stacking order, because this is your div parent, in which you already gave him .footer-contato{z-index:-1;} previously, ordering it to stay down at the stacking level.

The recommended here would be to bring the footer up all the content by assigning you a z-index:0;(or higher) which will result as follows:

#all{

    margin-bottom: 120px;

}
ul{
    border-bottom: 1px solid #ccc;
}


ul li{
    display: inline-block;
    padding: 10px
}

section{
    background: #ccc;
    padding: 20px 10px; 
    z-index: 1;
} 

.footer-contato{
    background: #f1f1f1;
    position: fixed;
    height: 100px;
    bottom: 0;
    width: 100%;
    z-index: 0;
}
<header>
    <nav>
        <ul>
            <li>home</li>
            <li>informações</li>
            <li>localização</li>
            <li>patrocinadores</li>
        </ul>
    </nav>
</header>
<div id="all">
    <section class="home">
        <h1>Home</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    </section>
    <section class="informacoes">
        <h1>Informações</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    </section>
    <section class="footer-contato">
        <h1> Footer fixed </h1>
        <a href="#">link</a>
    </section>
    <section class="local">
        <h1>Local</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    </section>
    <section class="patrocinadores">
        <h1>Patrocinadores</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    </section>
</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.