Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

z-index Not Working with Absolute Position

Tags:

html

css

If you take a look at my test website here you will see that the "Scroll Down" button is overlapping all my content, no matter what z-index I input. Is there a way to fix this issue? I realize that my position is absolute and that is most likely the issue, but if I state it as relative it is no longer set at the bottom of my page.

#scroll-down {
  height: 53px;
  width: 100%;
  display: table-cell;
  position: absolute;
  color: #fff;
  padding-top: 20px;
  padding-bottom: 20px;
  bottom: 0;
  left: 0;
  z-index: inherit;
  vertical-align: middle;
  background-color: rgba(0, 0, 0, 0.5);
  cursor: pointer;
  transition: all 0.25s ease-in-out;
}
#scroll-down:hover {
  color: #bae9ff;
  background-color: #fff;
}
<div class="site-wrap">

  <div class="background-image img-home">

    <div class="text">Welcome!</div>

    <a id="scroll-down noselect">
      <div id="scroll-down">Scroll Down
        <br />
        <object class="scroll-down-img" height="33" width="50"></object>
      </div>
    </a>

  </div>
like image 725
Anake.me Avatar asked Oct 24 '25 18:10

Anake.me


1 Answers

z-index becomes effective only for elements that have attribute position with value absolute or fixed or relative. Elements with position: static (which is the default for all elements) will not be affected by the z-index.

Easiest way in your case, add position: relative to .header, so your header tag becomes like this:

.header {
    width: 100%;
    background-position: center;
    background-repeat: no-repeat;
    z-index: 1000;
    position: relative;/* this will fix it */
}
like image 131
evilReiko Avatar answered Oct 26 '25 08:10

evilReiko