Fixed
fixed
uses position:fixed
to place elements on the corners of the current stacking context (usually the viewport).
Fixed position made easy
Use fixed
and you’ll get an element with fixed position on that side or corner.
<div class="fixed-topleft"> Top left </div><!-- ... other positions ... -->
Supports full-width and full-height fixed positions
Instead of specifying a corner, you just specify a side with fixed-*
.
Centering and Overlays made easy as well
Just use fixed-center
or fixed-overlay
to get these two layouts. Is there anything easier than this?
Intro
fixed
lets you place elements to the corners and sides of the viewport.
If you used new-stacking-context
, fixed
will be placed at the corners and sides of that stacking context instead.
Fixed Positions
Top positions
There are four top
positions.
fixed-topleft
: Place content at the top leftfixed-top
: Place content at the topfixed-topright
: Place content at the top rightfixed-topfull
: Place content at the top, spanning the full width
<div class="fixed-topleft"> Top left </div><div class="fixed-top"> Top </div><div class="fixed-topright"> Top right </div>
<div class="fixed-topfull">Top full</div>
Bottom positions
There are four bottom
positions.
fixed-bottomleft
: Place content at the bottom leftfixed-bottom
: Place content at the bottom, spanning the full widthfixed-bottomright
: Place content at the bottom rightfixed-bottomfull
: Place content at the bottom, spanning the full width
<div class="fixed-bottomleft"> Bottom left </div><div class="fixed-bottom"> Bottom </div><div class="fixed-bottomright"> Bottom right </div>
<div class="fixed-bottomfull">Bottom full</div>
Left positions
There are two left
positions.
fixed-left
: Place content at the leftfixed-leftfull
: Place content at the left, spanning the full height
<div class="fixed-left">Left </div>
<div class="fixed-leftfull">Left full </div>
Right positions
There are two right
positions.
fixed-right
: Place content at the rightfixed-rightfull
: Place content at the right, spanning the full height
<div class="fixed-right">Right </div>
<div class="fixed-rightfull">Right full </div>
Center
You can use fixed-center
to place an element in the center of the screen.
<div class="fixed-center">...</div>
Overlay
You can use fixed-overlay
to create an overlay over the entire screen.
<div class="fixed-overlay">...</div>
Nudging
You can nudge any fixed
element towards the center with --nudge
. Unlike Pos
, fixed
does not calculate inner border radius when you --nudge
.
<div class="fixed-topleft [--nudge:0.5rem]">...</div><div class="fixed-topright [--nudge:0.5rem]">...</div><div class="fixed-bottomleft [--nudge:0.5rem]">...</div><div class="fixed-bottomright [--nudge:0.5rem]">...</div>
Please purchase a license to view this content
This content is part of our premium documentation. To access it, you'll need to have an active license for one of these products.
If you already have a license, please login to access this content.
Intro
fixed
lets you place elements to the corners and sides of the viewport.
If you used new-stacking-context
, fixed
will be placed at the corners and sides of that stacking context instead.
Fixed Positions
Top positions
There are four top
positions.
fixed-topleft
: Place content at the top leftfixed-top
: Place content at the topfixed-topright
: Place content at the top rightfixed-topfull
: Place content at the top, spanning the full width
<div class="fixed-topleft"> Top left </div><div class="fixed-top"> Top </div><div class="fixed-topright"> Top right </div>
<div class="fixed-topfull">Top full</div>
Bottom positions
There are four bottom
positions.
fixed-bottomleft
: Place content at the bottom leftfixed-bottom
: Place content at the bottom, spanning the full widthfixed-bottomright
: Place content at the bottom rightfixed-bottomfull
: Place content at the bottom, spanning the full width
<div class="fixed-bottomleft"> Bottom left </div><div class="fixed-bottom"> Bottom </div><div class="fixed-bottomright"> Bottom right </div>
<div class="fixed-bottomfull">Bottom full</div>
Left positions
There are two left
positions.
fixed-left
: Place content at the leftfixed-leftfull
: Place content at the left, spanning the full height
<div class="fixed-left">Left </div>
<div class="fixed-leftfull">Left full </div>
Right positions
There are two right
positions.
fixed-right
: Place content at the rightfixed-rightfull
: Place content at the right, spanning the full height
<div class="fixed-right">Right </div>
<div class="fixed-rightfull">Right full </div>
Center
You can use fixed-center
to place an element in the center of the screen.
<div class="fixed-center">...</div>
Overlay
You can use fixed-overlay
to create an overlay over the entire screen.
<div class="fixed-overlay">...</div>
Nudging
You can nudge any fixed
element towards the center with --nudge
. Unlike Pos
, fixed
does not calculate inner border radius when you --nudge
.
<div class="fixed-topleft [--nudge:0.5rem]">...</div><div class="fixed-topright [--nudge:0.5rem]">...</div><div class="fixed-bottomleft [--nudge:0.5rem]">...</div><div class="fixed-bottomright [--nudge:0.5rem]">...</div>
This is the CSS for Fixed
.
[class*='Fixed'] { position: fixed;}
// Consider changing this to nudging with margins...// So top left right can be simpler[class*='Fixed-top'] { top: var(--nudge-y, var(--nudge, 0)); left: var(--nudge-x, var(--nudge, 0)); right: var(--nudge-x, var(--nudge, 0));}
.Fixed-topleft { right: auto;}
.Fixed-topright { left: auto;}
[class*='Fixed-bottom'] { bottom: var(--nudge-y, var(--nudge, 0)); left: var(--nudge-x, var(--nudge, 0)); right: var(--nudge-x, var(--nudge, 0));}
.Fixed-bottomleft { right: auto;}
.Fixed-bottomright { left: auto;}
[class*='Fixed-left'] { top: var(--nudge-y, var(--nudge, 0)); bottom: var(--nudge-y, var(--nudge, 0)); left: var(--nudge-x, var(--nudge, 0));}
.Fixed-lefttop { bottom: auto;}
.Fixed-leftbottom { top: auto;}
[class*='Fixed-right'] { top: var(--nudge-y, var(--nudge, 0)); bottom: var(--nudge-y, var(--nudge, 0)); right: var(--nudge-x, var(--nudge, 0));}
.Fixed-righttop { bottom: auto;}
.Fixed-rightbottom { top: auto;}
.Fixed-center { top: 50%; left: 50%; transform: translate(-50%, -50%);}
.Fixed-overlay { pointer-events: none; display: grid; inset-block: var(--nudge-y, var(--nudge, 0)); inset-inline: var(--nudge-x, var(--nudge, 0));}
Please purchase a license to view this content
This content is part of our premium documentation. To access it, you'll need to have an active license for one of these products.
If you already have a license, please login to access this content.
This is the CSS for Fixed
.
[class*='Fixed'] { position: fixed;}
// Consider changing this to nudging with margins...// So top left right can be simpler[class*='Fixed-top'] { top: var(--nudge-y, var(--nudge, 0)); left: var(--nudge-x, var(--nudge, 0)); right: var(--nudge-x, var(--nudge, 0));}
.Fixed-topleft { right: auto;}
.Fixed-topright { left: auto;}
[class*='Fixed-bottom'] { bottom: var(--nudge-y, var(--nudge, 0)); left: var(--nudge-x, var(--nudge, 0)); right: var(--nudge-x, var(--nudge, 0));}
.Fixed-bottomleft { right: auto;}
.Fixed-bottomright { left: auto;}
[class*='Fixed-left'] { top: var(--nudge-y, var(--nudge, 0)); bottom: var(--nudge-y, var(--nudge, 0)); left: var(--nudge-x, var(--nudge, 0));}
.Fixed-lefttop { bottom: auto;}
.Fixed-leftbottom { top: auto;}
[class*='Fixed-right'] { top: var(--nudge-y, var(--nudge, 0)); bottom: var(--nudge-y, var(--nudge, 0)); right: var(--nudge-x, var(--nudge, 0));}
.Fixed-righttop { bottom: auto;}
.Fixed-rightbottom { top: auto;}
.Fixed-center { top: 50%; left: 50%; transform: translate(-50%, -50%);}
.Fixed-overlay { pointer-events: none; display: grid; inset-block: var(--nudge-y, var(--nudge, 0)); inset-inline: var(--nudge-x, var(--nudge, 0));}
Fixed
Modifiers
Class | Description |
---|---|
fixed-topleft | Place content at the top left corner |
fixed-top | Place content at the top |
fixed-topright | Place content at the top right corner |
fixed-topfull | Place content at the top, spanning the full width |
fixed-bottomleft | Place content at the bottom left corner |
fixed-bottom | Place content at the bottom |
fixed-bottomright | Place content at the bottom right corner |
fixed-bottomfull | Place content at the bottom, spanning the full width |
fixed-left | Place content at the left |
fixed-leftfull | Place content at the left, spanning the full height |
fixed-right | Place content at the right |
fixed-rightfull | Place content at the right, spanning the full height |
fixed-overlay | Creates an overlay |
fixed-center | Place content in the center of the overlay |
CSS Variables
Variable | Default | Description |
---|---|---|
--nudge | 0 | Amount to nudge towards the center on both block and inline axis |
--nudge-x | 0 | Amount to nudge towards the center on the inline axis |
--nudge-y | 0 | Amount to nudge towards the center on the block axis |
Please purchase a license to view this content
This content is part of our premium documentation. To access it, you'll need to have an active license for one of these products.
If you already have a license, please login to access this content.
Fixed
Modifiers
Class | Description |
---|---|
fixed-topleft | Place content at the top left corner |
fixed-top | Place content at the top |
fixed-topright | Place content at the top right corner |
fixed-topfull | Place content at the top, spanning the full width |
fixed-bottomleft | Place content at the bottom left corner |
fixed-bottom | Place content at the bottom |
fixed-bottomright | Place content at the bottom right corner |
fixed-bottomfull | Place content at the bottom, spanning the full width |
fixed-left | Place content at the left |
fixed-leftfull | Place content at the left, spanning the full height |
fixed-right | Place content at the right |
fixed-rightfull | Place content at the right, spanning the full height |
fixed-overlay | Creates an overlay |
fixed-center | Place content in the center of the overlay |
CSS Variables
Variable | Default | Description |
---|---|---|
--nudge | 0 | Amount to nudge towards the center on both block and inline axis |
--nudge-x | 0 | Amount to nudge towards the center on the inline axis |
--nudge-y | 0 | Amount to nudge towards the center on the block axis |