Position

Utilities for controlling the position of an element.

In this article

Class Properties
.static position: static;
.relative position: relative;
.absolute position: absolute;
.absolute-top @include absolute-top();
.absolute-center @include absolute-top();
.fixed position: fixed;
.fixed-top @include fixed-top();
.fixed-bottom @include fixed-bottom();
.sticky position: sticky;
.sticky-top @include sticky-top();
.initial position: initial;

Usage

Static

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

<div class="static bg-gray-600 p-4">
  Static parent
  <div class="absolute bottom-0 left-0 bg-gray-700 p-4">
    Absolute child
  </div>
</div>

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

Relative

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

<div class="static bg-gray-600 p-4">
  Relative parent
  <div class="absolute bottom-0 left-0 bg-gray-700 p-4">
    Absolute child
  </div>
</div>

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

Absolute

Use .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.

<div class="relative p-4 bg-gray-400">
  Relative parent
  <div class="static p-4 bg-gray-500">
    Static parent
    <div class="absolute p-4 top-0 right-0 text-gray-100 bg-gray-600">
      Absolute child
    </div>
    <div class="inline-block p-4 text-gray-100 bg-gray-600">
      Static sibling
    </div>
  </div>
</div>

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

Fixed

Use .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.

Sticky

Use .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.

Sticky positioning is not supported in IE11

Variants

By default, only responsive variants are generated for position utilities.

Responsive

To control the position of an element at a specific breakpoint, add a {screen}: prefix to any existing position utility.

For example, use .md:fixed to apply the fixed utility at only medium screen sizes and above.

Hover-state

To include hover-state variants like .hover:fixed, add "position" to the $hover-variants variable when recompiling your CSS:

$hover-variants: (
  // ...
  "position",
);

Questions or feedback about this article? Let us know