Difference between absolute and relative positioning ? [Unsolved] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Difference between absolute and relative positioning ? [Unsolved]

In the following code even if i change cont element to have absolute positioning nothing is changing or even if you put the opposite values of position on child and parent , still nothing will change! https://code.sololearn.com/WzsOBPc2Xybw/?ref=app

14th Jul 2021, 10:53 AM
Abhay
Abhay - avatar
6 Answers
+ 3
Run the code to get understand of css positioning https://code.sololearn.com/WNrAqPm0nhW9/?ref=app
14th Jul 2021, 4:34 PM
Calviղ
Calviղ - avatar
16th Jul 2021, 6:30 AM
Anurag Saikia
+ 1
1. Body the very first element. and div in default displayed as block, which means in default gets all the parents area if other is not written like: width: 20% or height 30px etc. 2. As you determine the width and height of all div elements... they will get exectly those parameters. 3. When you give position: absolute. It take place not relative to body. But relative to parent element. But as far as the sizes of two divs are equal child element had to go out of the parent's territory
14th Jul 2021, 12:34 PM
Shadoff
Shadoff - avatar
0
relative position element relatively to its initial position absolute position element relatively to initial position of first positionned parent
14th Jul 2021, 11:00 AM
visph
visph - avatar
0
visph ty for answering but i still don't understand what you mean by first positioned parent.An example would be much appreciated . Anyway i will try to look more into this myself, i have gone through many articles but nothing makes sense to me yet .
14th Jul 2021, 11:52 AM
Abhay
Abhay - avatar
0
first positioned parent means nearest parent with css 'position' property set to anything but static ^^ if no such parent, root element is used (html/body)
14th Jul 2021, 11:54 AM
visph
visph - avatar