I am currently dealing with a situation where I want to create a slide-in side menu that remains sticky. However, when I apply the position: sticky CSS property to my menu container, it causes the entire menu to be displayed (instead of being pushed off the screen with a negative left value), and the button used to open and close the menu stops functioning.
Interestingly, the menu animation works perfectly fine when the container is set to absolute positioning. This leads me to question whether there is a missing element in order for both functionalities to work together, or if it is simply not possible to achieve the desired outcome in the way I am attempting.
You can view the issue in action on this CodePen
Below is an extract of the CSS:
#side-menu-container{
width: 100%;
max-width: 300px;
height: 100%;
min-height: 1000px;
position: absolute;
left: 0;
top: 0;
}
/* Changes to positioning cause issues here */
#side-menu{
width: 100%;
max-width: 330px;
padding: 1rem 0;
background: #cccccc;
position: sticky;
left: -300px;
top: 100px;
}
#side-menu ul{
text-align: center;
}
#side-menu li{
list-style-type: none;
margin: 1rem;
}
#side-menu-btn{
width: 50px;
height: 50px;
position: absolute;
left: 100%;
background: #cccccc;
cursor: pointer;
}
#side-menu.side-menu-open{
left: 0;
}
I have attempted setting the main container element, which holds both the button and the menu, as relative, and I have also experimented with applying z-index values to different elements, but these attempts have not provided a solution. This makes me believe that there might not be an overlapping element causing the issue.