<!DOCTYPE html>
<html lang="pl">
<head>
<title>Test z-index</title>
<style>
.div1 {position:relative; z-index:1; margin:10px; background:#eee; }
.div2 {position:absolute; top:14px; z-index:999; background:blue; }
</style>
</head>
<body>
<div class="div1" >Lorem ipsum ... <div class="div2">This element I want to be on top!</div> Phasellus fermentum in, dolor.</div>
<div class="div1" >Suspendisse a pellentesque dui, non felis.</div>
</body>
</html>
I am facing an issue with the stacking order of my CSS elements. I have two divs with the class "div1" that are relatively positioned.
Inside the first div, I placed another div with the class "div2" which is absolutely positioned. My goal is to make sure that "div2" appears on top of both instances of "div1."
Currently, "div2" is on top of the first "div1," but not the second one. How can I adjust my CSS code to ensure that "div2" remains on top of all elements on the page?