<!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>
我有两个div1
相对定位的元素。
在第一个元素内我放了一个绝对元素div2
。我想将div2
元素放在两个div1
元素(网站上的所有元素)之上。
The problem is that div2
is on top of first div1
element, but it's not on top of the second div1
element.
How can I fix it? How can I edit my css code?