monks/position
The position CSS property sets how an element is positioned in a document. The {{Cssxref(“top”)}}, {{Cssxref(“right”)}}, {{Cssxref(“bottom”)}}, and {{Cssxref(“left”)}} physical properties and the {{cssxref(“inset-block-start”)}}, {{cssxref(“inset-block-end”)}}, {{cssxref(“inset-inline-start”)}}, and {{cssxref(“inset-inline-end”)}} flow-relative logical properties can be used to determine the final location of positioned elements.
Values
pub const absolute: #(String, String)
- : The element is removed from the normal document flow, and no space is created for the element in the page layout. The element is positioned relative to its closest positioned ancestor (if any) or to the initial containing block. Its final position is determined by the values of
top,right,bottom, andleft. This value creates a new stacking context when the value ofz-indexis notauto. The margins of absolutely positioned boxes do not collapse with other margins.
pub const fixed: #(String, String)
- : The element is removed from the normal document flow, and no space is created for the element in the page layout. The element is positioned relative to its initial containing block, which is the viewport in the case of visual media. Its final position is determined by the values of
top,right,bottom, andleft. This value always creates a new stacking context. In printed documents, the element is placed in the same position on every page.
pub const relative: #(String, String)
- : The element is positioned according to the normal flow of the document, and then offset relative to itself based on the values of
top,right,bottom, andleft. The offset does not affect the position of any other elements; thus, the space given for the element in the page layout is the same as if position werestatic. This value creates a new stacking context when the value ofz-indexis notauto. Its effect ontable-*-group,table-row,table-column,table-cell, andtable-captionelements is undefined.
pub const revert_layer: #(String, String)
pub const static: #(String, String)
- : The element is positioned according to the Normal Flow of the document. The {{cssxref(“top”)}}, {{cssxref(“right”)}}, {{cssxref(“bottom”)}}, {{cssxref(“left”)}}, and {{cssxref(“z-index”)}} properties have no effect. This is the default value.
pub const sticky: #(String, String)
- : The element is positioned according to the normal flow of the document, and then offset relative to its nearest scrolling ancestor and containing block (nearest block-level ancestor), including table-related elements, based on the values of
top,right,bottom, andleft. The offset does not affect the position of any other elements. This value always creates a new stacking context. Note that a sticky element “sticks” to its nearest ancestor that has a “scrolling mechanism” (created whenoverflowishidden,scroll,auto, oroverlay), even if that ancestor isn’t the nearest actually scrolling ancestor. > [!NOTE] > At least one inset property ({{cssxref(“top”)}}, {{cssxref(“inset-block-start”)}}, {{cssxref(“right”)}}, {{cssxref(“inset-inline-end”)}}, etc.) needs to be set to a non-autovalue for the axis on which the element needs to be made sticky. If bothinsetproperties for an axis are set toauto, on that axis thestickyvalue will behave asrelative.