0

I'm trying to understand why in the following codepen: https://codepen.io/benrhere/pen/XWRmVjr

setting position: relative on the second sibling affects (hides) the visibility of the first sibling (with Chrome 91.0.4472.124). You can see the problem in the first square div below, while the second square div does not have this problem. The only difference is that the second sibling is marked position: relative. It seems that this places the first sibling behind in stacking order, though I would have expected that applying position: relative only would affect its child elements' stacking order, not its siblings.

Ultimately, I'm going to move away from using float: right, but I'm just curious about this.

Picture showing possibly differing stacking orders

<html>
  <body>
    <div class="outer">
      <span class="floated">X</span>
            <div id="relative">Y</div>
    </div>
    <hr />
    <div class="outer">
      <span class="floated">X</span>
      <div id="notRelative">Y</div>
    </div>
  </body>
</html>
BenjiFB
  • 4,545
  • 10
  • 46
  • 53

1 Answers1

-1

Default position of an element is static but when you give a position to the element other than static, its given a z-index. Thats why your span is below the stack index of the div.