Tell about the CSS property position: what values are available and what are their features?
sobes.tech AI
Answer from AI
The CSS property position determines how an element is positioned on the page. Main values:
-
static— default value. The element is positioned in the normal flow of the document, ignoringtop,left, etc. -
relative— the element is positioned relative to its normal position. You can offset it usingtop,left, but it still occupies space in the flow. -
absolute— the element is removed from the normal flow and positioned relative to the nearest positioned ancestor (relative,absolute,fixed). If none exists, relative to the browser window. -
fixed— the element is fixed relative to the browser window and does not move when scrolling. -
sticky— a hybrid ofrelativeandfixed. The element behaves asrelativeuntil it reaches a specified position during scrolling, then it becomes fixed.
Features:
- Elements with
absoluteandfixeddo not occupy space in the flow, affecting the layout of neighboring elements. relativeallows shifting the element without breaking the flow.stickyis useful for creating fixed headers, menus, etc.
Example:
.header {
position: sticky;
top: 0;
background: white;
}