0

In an application I am working I found a top level parent container with position: relative like so:

<div style="position: relative">
    <!--render body content here-->
</div>

Many HTML views are rendered in this parent container. Not single HTML has absolute positioning.

This is not my code, so I want to make sure that the inline CSS style="position: relative" serves no purpose and can be deleted.

There isn't a point to a parent container have position:relative if there is not descendants with position:absolute or position:relative, correct? As there is not any child container that has position defined at all, that I can find.

Brian Ogden
  • 18,439
  • 10
  • 97
  • 176
  • 1
    Nope. You can move a relative positioned element using top, right, bottom or left. You can also set it's z-index value, so it will be above static elements, or elements with z-index. – Ori Drori Oct 25 '19 at 16:08
  • @OriDrori no descendant is relative either I will update my question – Brian Ogden Oct 25 '19 at 16:12
  • 1
    it affect the painting order: https://stackoverflow.com/a/52698754/8620333 so it doesn't need to contain child with particular properties. An element with position:relative will be painted later that a one without. But without your full code no one can say if it's useless or not. – Temani Afif Oct 25 '19 at 18:25

0 Answers0