Search code examples
javascripthtmlcsscss-position

Absolute element going behind sticky/fixed element


I have a simple Dropdown and a sticky container to the right. The dropdown keeps going behind the sticky container as such:

Image

I tried:

  • changing the right container to position fixed
  • changing z-index of both divs

The dropdown with position absolute is article-actions-dropdown-content The sticky container is right-sidebar-container.

Sticky element:

.right-sidebar-container {
    height: 550px;
    width: 98%;
    background-color: red;
    display: block;
    margin-left: auto;
    margin-right: auto;
    top: 20%;
    margin-top: 10px;
    position: sticky;
    margin-bottom: 20px;
    transition: 0.5s;
}

Absolute element:

.article-actions-dropdown-content {
    position: absolute;
    background-color: #fff;
    box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
    min-width: 160px;
    overflow: auto; 
    border: 1px solid #ebebeb;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.1s ease-in;
    overflow: hidden;
    visibility: hidden;
}

Solution

  • Try adding z-index: 1 to the element with class article-actions-dropdown-wrapper.That is,

    .article-actions-dropdown-wrapper{
      z-index: 1
    }