0

Every doc I read about absolute position says: "element is positioned relative to its closest positioned ancestor"

But when I use it with the sibling with position: relative that is before it, element with position absolute don't want to position itself relative to the ancestor, but it takes into account the position of the relative sibling in the document flow. I can't understand why is that. Absolute should be absolute, not relative to the whatever sibling element... Can somebody explain it to me ?

<div>
 <div style="position:relative;">element1</div>
 <div style="position:absolute;">element2</div>
</div>
Melon Eusk
  • 35
  • 3

1 Answers1

3

Absolute positioned elements are moved from their static position - that is, the position they would have in normal flow if they weren't absolute positioned.

But you haven't moved it anywhere. You need to give it at least one of top, bottom, left, right, or their flow-relative equivalents inset-block-start, inset-block-end, inset-inline-start, inset-inline-end or their shorthands.

Alohci
  • 78,296
  • 16
  • 112
  • 156