Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is position absolute rendered above position static?

I have a simple absolute div and another normal div coming behind. Why is the absolute div rendered above the other?

I know that I can fix it with z-index - But what is the reason?

JSBIN: http://jsbin.com/yadoxiwuho/1

<style>
    .with-absolute {
      position:absolute;
      top:0px;
      bottom:0px;
      background-color:red
    }
    .other {
      background-color:yellow;
    }
  </style>
   </head>
<body>
  <div class="with-absolute">Hello</div>
  <div class="other">Why is this not on top? It comes last</div>
</body>
like image 730
zolv Avatar asked May 04 '15 10:05

zolv


1 Answers

The paint order of elements is determined by CSS 2.1 spec, E.2 Painting order

Static positioned elements are painted in steps 4 to 7. Absolute positioned elements with a z-index of auto or 0 are painted in step 8, so are always on top.

like image 88
Alohci Avatar answered Sep 28 '22 08:09

Alohci