Position

Utilities for controlling how an element is positioned in the DOM.

React propsCSS Properties
position={keyword}position: {keyword};

Static

Use position="static" to position an element according to the normal flow of the document.

Any offsets will be ignored and the element will not act as a position reference for absolutely positioned children.

<x.div position="static"> <p>Static parent</p> <x.div position="absolute" bottom={0} left={0}> <p>Absolute child</p> </x.div> </x.div>

Relative

Use position="relative" to position an element according to the normal flow of the document.

Offsets are calculated relative to the element's normal position and the element will act as a position reference for absolutely positioned children.

<x.div position="relative"> <p>Static parent</p> <x.div position="absolute" bottom={0} left={0}> <p>Absolute child</p> </x.div> </x.div>

Absolute

Use position="absolute" to position an element outside of the normal flow of the document, causing neighboring elements to act as if the element doesn't exist.

Offsets are calculated relative to the nearest parent that has a position other than position="static", and the element will act as a position reference for other absolutely positioned children.

<x.div position="static"> {/* Static parent */} <x.div position="static"> <p>Static child</p> </x.div> <x.div display="inline-block"> <p>Static sibling</p> </x.div> {/* Static parent */} <x.div position="absolute"> <p>Absolute child</p> </x.div> <x.div display="inline-block"> <p>Static sibling</p> </x.div> </x.div>

Fixed

Use position="fixed" to position an element relative to the browser window.

Offsets are calculated relative to the viewport and the element will act as a position reference for absolutely positioned children.

<div> <x.div position="fixed">Fixed child</div> Scroll me! Lorem ipsum... </div>

Sticky

Use position="sticky" to position an element as relative until it crosses a specified threshold, then treat it as fixed until its parent is off screen.

Offsets are calculated relative to the element's normal position and the element will act as a position reference for absolutely positioned children.

<div> <x.div position="sticky" top={0}> Sticky Heading 1 </x.div> <x.p py={4}>Quisque cursus...</x.p> </div> <div> <x.div position="sticky" top={0}> Sticky Heading 2 </x.div> <x.p py={4}>Integer lacinia...</x.p> </div> <div> <x.div position="sticky" top={0}> Sticky Heading 3 </x.div> <x.p py={4}>Nullam mauris...</x.p> </div>

Responsive

To change how an element is positioned only at a specific breakpoint, use responsive object notation. For example, adding the property position={{ md: "absolute" }} to an element would apply the position="absolute" utility at medium screen sizes and above.

<x.div position={{ md: 'absolute' }} />

For more information about xstyled's responsive design features, check out Responsive Design documentation.

Edit this page on GitHub