+ 11

What is difference between position absolute & relative ?And whats wrong with this code ?? [ Solved ]

https://code.sololearn.com/WGbD0RtXM29A/?ref=app https://code.sololearn.com/WI6u6yHc47Y6/?ref=app In this code if we put the % value for height & width in position relative box it doesnt work , and if we put pixel value it work , why ??

24th Nov 2020, 10:26 AM
Dipendra
Dipendra - avatar
5 odpowiedzi
+ 1
Dê@d👋🏻🎭 ( Deactivated ) % doesn't work because box1's dimensions depend on their parent element's dimensions (body) which you have not specified. Body element can take as much height and width as specified, or it will keep adding the dimensions until where the last specified element is visible. I believe what you want to archive can be solved by using viewport-height(vh) and viewport-width(vw)
24th Nov 2020, 7:23 PM
Devotha Mwenda
Devotha Mwenda - avatar
+ 5
🇮🇳Vivek🇮🇳 and whats wrong with the code why % value not working 🙁
24th Nov 2020, 10:34 AM
Dipendra
Dipendra - avatar
+ 4
position relative means elements position will always be relative to its parent element. absolute position means the position of elements will be relative to Window objects. This is very handy when we create modal.
24th Nov 2020, 10:33 AM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar
+ 3
Dê@d👋🏻🎭 ( Deactivated ) you are setting height and width not position of any element. Try “top, right, left, bottom” height : 10% means 10% of height of html document. Same for width.
24th Nov 2020, 10:38 AM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar
+ 1
Dê@d👋🏻🎭 ( Deactivated ) the difference between position relative and absolute is: Relative: will make the elements appear as static(default) until you specify how far from the top and left it should move in association with its axis. It gives you a choice of not using margin. Absolute: the element will act as if other sibling elements are not there. It will position its self in correspondence to the last element with a position property (usually its parent and siblings if any).But if the position is not specified in its parent element, it will position its self in correspondence to the body element. From there you can specify how further from left or top you want the element to move.
24th Nov 2020, 7:41 PM
Devotha Mwenda
Devotha Mwenda - avatar