How to make sticky element appear behind another element?

https://jsfiddle.net/30suam6z/1/ .first { height: 100vh; background-color: red; position: relative; z-index: 2; /* Increase z-index to ensure it covers .test */ } .second { height: 100vh; background-color: yellow; position: relative; z-index: -1; } .test { width: 95%; height: 50px; background-color: green; margin: 0 auto; position: sticky; top: 70%; z-index: -1; } .third { height: 100vh; background-color:… Read More How to make sticky element appear behind another element?

HTML/CSS Position sticky is not working properly

I am trying to make a div position: sticky; but it doesn’t work, here’s my code: body { height: 1000px; } header { position: absolute; width: 100%; z-index: 100; } .top-navbar { height: 100px; background-color: green; } nav { position: -webkit-sticky !important; position: sticky; top: 0; align-self: flex-start; background-color: orange; } <header> <div class=”top-navbar”> <h2>top… Read More HTML/CSS Position sticky is not working properly