DEV Community

Shadab Ali
Shadab Ali

Posted on

1

When Johnny bhaiya start taking frontend interviews

Which position are you comfortable? and how do they differ?
.
.
.
.
.
.
Question: How absolute, relative, fixed and static position differ?

Answer:

🔥absolute : it place an element exactly where you want to place it. absolute position is actually set relative to the element's parent. if no parent available then relatively place to the page itself.

🔥relative, is position an element relative to itself (from where the element would be placed, if u don't apply relative positioning). for example, if u set position relative to an element and set top: 10px, it will move 10px down from where it would be normally.

🔥fixed, element is positioned relative to viewport or the browser window itself. viewport doesn't changed if u scroll and hence fixed element will stay right in the same position.

🔥static, element will be positioned based on the normal flow of the document. usually, u will use position static to remove other position might be applied to an element

Z index only works on positioned elements (absolute, relative, or fixed)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (1)

Collapse
 
shacodes profile image
Shadab Ali •

read and play with css position
frontendchef.com/blog/learn-positi...

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay