-1

When do we use 'position:relative' in a div, does it mean that the elements inside it will have a relative positioning or his own position will be relative to his parent?

Sasha Nicolas
  • 159
  • 1
  • 9

2 Answers2

0

It means that the div is positioned relative to its containing element.

user229044
  • 232,980
  • 40
  • 330
  • 338
0

It means its own position will be relative to is closest positioned parent ("positioned" meaning any value for position other than static, or blank).

Absolutely relative positioned elements behave very similar, their position is also relative to the closest positioned parent. The difference is:

  • position: absolute: the element is taken "out of the flow" when the layout is processed, so other elements behave as if the absolute element didn't exist.

  • position: relative: the element is kept "in the flow" when the layout is processed, and other elements behave as if it has position: static.

bfavaretto
  • 71,580
  • 16
  • 111
  • 150