0

I'm looking at this tutorial https://www.w3schools.com/css/css_dropdowns.asp. I thought that position:relative was used to position the element relative to its normal position.

Why is it needed in order to position its children? Isn't position:absolute on children enough?

Dulguun Otgon
  • 1,925
  • 1
  • 19
  • 38
  • 1
    The usage in that tutorial is more for the `absolute`ly positioned child. When you position something absolutely, it's relative to the closest `relative` or `absolute` parent. See if this helps https://stackoverflow.com/questions/10487292/position-absolute-but-relative-to-parent – sallf Nov 20 '19 at 05:58
  • I guess I missed that part about `absolute`. Now it makes sense. – Dulguun Otgon Nov 20 '19 at 06:04

1 Answers1

0

Suppose you have an element "A" with position:absolute, the element "A" will be positioned based on the body. It will not have relation to its parent elements. But if the element "A" have a parent "B" with position: relative, the position of "A" will be related on this parent "B".

Pons Purushothaman
  • 2,225
  • 1
  • 14
  • 23