Search code examples
htmlcssmobilesquarespace

Drop down menu hides behind content of page


I'm working on making a Squarespace page with custom CSS to be mobile responsive. In a mobile screen, my page has a drop down menu with the different links for the page. My problem is that in certain pages (such as Music or Watch) when you click on the menu button, the drop down menu hides behind the content of the page. I know this has to do with using position: absolute, but i have not found a way to have the placement of the menu button and drop down list as I want it by using position: relative. This is my CSS for the menu:

#mobileNav {
  background: none;
  position: absolute;
  top: 20%;
  left: 0;
  right: 0;
}

#mobileNav .wrapper {
  border-bottom-style: none;
  border-bottom-color: none;
}

You can view the page at richiequake.com using the password Help123. Is there another way I can have the placement of the menu button and the drop down list and have the list "push" the content of the page down so the link list is visible?


Solution

  • Basically, are you are missing is the z-index property. Which will place the container #mobileNav in a higher layer.

    By making this change (adding z-index property to your CSS selector):

    #mobileNav {
       background: none;
       position: absolute;
       top: 20%;
       left: 0;
       right: 0;
    
      z-index: 1;
    }
    

    I can now see the menu links in all pages. You can read more about the z-index spec here.

    UPDATE - To also push the content down while using absolute positioning:

    As you are already using a custom class to toggle the menu links, you can use that to also toggle the content section.

    Add a selector rule as following to your stylesheet:

    .menu-open~section#page {
         transform: translateY(355px);
    }
    

    What this will do is, when the menu-open class is in the document, the sibling section with id of page, will be pushed down 355px.

    You can also add a some kind of animation if you want a smoother effect on pushing the content down, like so:

    #page {
      margin-top: 100px;
      margin-bottom: 100px;
      opacity: 1;
      position: relative;
    
      transition: transform .3s linear;
    }
    

    I just added the transition, where the .3s is the time that the transition will take.