I have created a custom element above the header that has a menu item on it. I am unable to find any solution into making that element always stick to top of the page and stay above the header, instead of hiding under it when scrolling. The header element is already always on top. Ive tried coding, using the sidekick, adding CSS but it didnt work. If anyone has the solution to this please help.
after adding this into theme CSS and saving nothing changed. The top bar still dissapears when scrolling down. Just to let you know, the section I want sticky was made with the Shopify AI. I have tried making a new one with a “sticky” option, but it never seemed to work.
Could there be something that we can add to the code itself that works?
Hey @Dan-From-Ryviu your code pretty much seems correct. Make sure the z-index of the announcement is higher than the main header and both of their z-indexes is higher than the main tag, that is everything else inside the page. So make a z-index lower in the main tag.
Hello, thanks for the code. Sadly it still is not working. Do I need to change or add specific code to the custom element or header element? Maybe If I force the header element to stay lower down?
But after deleting it from there and adding the latest code to the theme.liquid it seems to work. You can check on the page yourself, the custom bar is always on top.
You probably need to adjust the z-index on your custom element so it sits above everything else. The header likely has a higher z-index number which is why your element goes under it when you scroll. Try adding position: sticky, top: 0, and z-index: 9999 to your custom element’s CSS and see if that keeps it on top.