Using top, right, bottom, and left in CSS
The top, right, bottom, and left properties in CSS determine the offset of an element from its containing block. These properties only work on elements that have a position value other than static (relative, absolute, fixed, or sticky).
top – Moves the element down (positive values) or up (negative values) relative to its positioned context.
right – Moves the element left (positive values) or right (negative values) relative to its positioned context.
bottom – Moves the element up (positive values) or down (negative values) relative to its positioned context.
left – Moves the element right (positive values) or left (negative values) relative to its positioned context.
For relative, offsets move the element visually but do not remove it from the flow.
For absolute and fixed, offsets position the element relative to the nearest positioned ancestor or viewport, and the element is removed from the normal flow.
For sticky, offsets define the threshold at which the element becomes fixed within its container.
Using these offset properties allows precise placement of elements. The effect depends on the element's positioning type and the reference point (parent container, viewport, or original position).
Use offsets only on elements with position set to relative, absolute, fixed, or sticky.
Combine offsets with z-index to manage overlapping elements.
For relative elements, avoid large offsets that disrupt the layout.
For absolute/fixed elements, ensure the parent context is correctly positioned for predictable placement.
Test offsets across screen sizes for responsive layouts.