Search code examples
javascripthtmlcsspositionhamburger-menu

UL Background doesn`t show when i add position absolute


I want to build a hamburger menu and I don't know why when I add position absolute to my UL(links-list) his background doesn`t show.It only shows the links and the border-bottom. I will post maybe someone will spot the issue. Thank you in advance. I will write here something because I need to have more words to post the question.

.header {
  width: 100%;
  display: block;
  height: 0;
  z-index: 1;
  .header-content {
    display: block;
    .logo {
      display: none;
    }
    .links-list {
      display: block;
      position: absolute;
      top: 0;
      left: 0;
      z-index: 2;
      margin: 0;
      width: 100%;
      background: #505050;
      height: 0;
      .close {
        display: block;
        & a {
          padding: 0 .5rem;
        }
      }
      & li {
        border-bottom: 1px solid #404040;
      }
    }
  }
}

.open {
  height: auto !important;
}

#burger-menu {
  display: block;
  height: 40px;
  width: 100%;
  background: url(/Core/img/burger.png)no-repeat 98% center;
  background-size: 70px;
  background-color: red;
}
<header class="header ">
  <div class="container">
    <div class="header-content">
      <a href="#" id="burger-menu">
      </a>
      <img src="/Core/img/logo1.jpg" class="logo" alt="logo" />
      <ul class="links-list">
        <li class="close"><a href="#"><i class="fas fa-times"></i></a></li>
        <li><a href="/Core/index.html">Home</a></li>
        <li><a href="/Core/biography.html">Bio</a></li>
        <li><a href="/Core/training.html">Training</a></li>
        <li><a href="#">Academy</a></li>
        <li><a href="#">Gallery</a></li>
        <li><a href="#">Store</a></li>
        <li><a href="/Core/contact.html">Contact</a></li>
      </ul>
      <div class="overlay"></div>
    </div>
  </div>
</header>


Solution

  • It's because you have height: 0 on .links-list. When positioning elements absolutely, in most, if not all, cases you need to make sure the height has a positive value so the background has an area to draw on.