All CSS Property
Deep Chand
1 min read
static: This is the default position value. Elements with
position: static
is positioned according to the normal flow of the document..box { position: static; }
relative: Elements with
position: relative
are positioned relative to their normal position in the document flow. You can use thetop
,bottom
,left
, andright
properties to adjust the position..box { position: relative; top: 10px; left: 20px; }
absolute: Elements with
position: absolute
are positioned relative to the nearest positioned ancestor (or the containing block if no positioned ancestor is found). If there is no positioned ancestor, it is positioned relative to the initial containing block (the viewport).
.box {
position: absolute;
top: 50px;
right: 20px;
}
- fixed: Elements with
position: fixed
are positioned relative to the viewport and do not move even if the page is scrolled.
.box {
position: fixed;
top: 0;
right: 0;
}
- sticky: Elements with
position: sticky
is positioned based on the user's scroll position. They behave likeposition: relative
within their parent element until a specified offset threshold is reached. Then they becomeposition: fixed
and "stick" to a specific position.
.box {
position: sticky;
top: 20px;
}
0
Subscribe to my newsletter
Read articles from Deep Chand directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by