Ben Aston
Ben Aston

Reputation: 55729

Static versus relative positioning in CSS

Relative positioning is the same as the default static positioning, except you can use offset values (top, left, etc.).

Relative seems objectively more powerful that static positioning.

Is there any disadvantage to resetting in CSS all elements to be relative (and overriding for absolute as required)?

Upvotes: 0

Views: 115

Answers (2)

Supr
Supr

Reputation: 19022

Absolute positioned elements are relative to the closest relative container. If you set everything to relative then it will be a PITA to use absolute positioning in cases where you want your absolute element to be positioned relative to an ancestor further up the tree, because the parent of the absolute element will always be relative.

Upvotes: 1

Quentin
Quentin

Reputation: 943510

Relative positioning establishes a new context for absolutely positioned descendants (which are positioned with the respect to the edges of their closest ancestor that is not statically positioned).

Upvotes: 3

Related Questions