CSS position
The CSS position
property specifies how an element is positioned in a document. There are five different position values in CSS: static
, relative
, absolute
, fixed
, and sticky
.
Static Position
The default positioning method is static
. An element with a static
position is positioned according to the normal flow of the document. This means that it will appear in the order it appears in the HTML code.
Relative Position
An element with a relative
position is positioned relative to its normal position. This means that you can move it from its original position without affecting the layout of other elements.
Absolute Position
An element with an absolute
position is positioned relative to the nearest positioned ancestor. If there is no positioned ancestor, it is positioned relative to the initial containing block, which is usually the <body>
element.
Fixed Position
An element with a fixed
position is positioned relative to the viewport, which means it always stays in the same place even when the page is scrolled.
Sticky Position
An element with a sticky
position is positioned based on the user's scroll position. It behaves like relative
positioning until a specified scroll point is reached, then it "sticks" in place.