Stack
stack
creates elements that are stacked on top of each other with CSS Grid.
Stack elements without position: absolute
stack
uses CSS Grid to stack elements together.
<div class="stack"> <div class="background"> Background </div> <div> Content </div> <div class="foreground"> Foreground </div></div>
The entire stack contains the same height and width
If one layer has more content than others, the entire stack expands in accordance to that layer.
<div class="stack"> <div class="background"> Background </div> <div> Lots of content ... </div> <div class="foreground"> Foreground </div></div>
Make complex layouts with stacking elements a cinch
This becomes super easy and doable because stack
ed elements contains the same height
and width
.
So backgrounds are automatically contained within the stack — no overflow headaches!
<div class="stack"> <div class="background"> SVG Background here ... </div> <div> Content </div> <div class="foreground"> Pill #1 </div> <div class="foreground"> Pill #2 </div> </div></div>
This example uses edge
to position the pills on
the foreground
.
Intro
stack
lets you stack elements on top of each other. It is useful for creating overlapping layers (very much like having layers in Photoshop or other design applications).
When combined with positioning classes like edge
, stack
lets you create complex layouts with backgrounds, content, and foregrounds easily.
Basic
stack
uses CSS Grid that has one column and one row. Everything is placed in that column and row.
<div class="stack"> <div>One<div> <div>Two<div></div>
Order of Layers
You can have an unlimited number of layers in a stack
. The order of layers are determined by two factors:
- Whether they have a
background
orforeground
class - The order in which they are placed in the HTML
backgrounds
will always be placed at the bottom of the stack, while foregrounds
will always be placed at the top.
<div class="stack"> <div class="background"> Background </div> <div class="background"> Background 2 </div> <div> Content </div> <div> Content 2 </div> <div class="foreground"> Foreground </div> <div class="foreground"> Foreground 2 </div></div>
Backgrounds
background
layers let you add miscellaneous design items beyond what a standard background
property could achieve — so you can do more than just colours and gradients.
For example, you can use SVG to make beautiful backgrounds using patterns from Pattern Monster, Hero Patterns and many others.
Foregrounds
foreground
layers let you place elements before the content. This is useful for placing elements like badges, labels, or other elements that should be on top of the content.
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
stack
lets you stack elements on top of each other. It is useful for creating overlapping layers (very much like having layers in Photoshop or other design applications).
When combined with positioning classes like edge
, stack
lets you create complex layouts with backgrounds, content, and foregrounds easily.
Basic
stack
uses CSS Grid that has one column and one row. Everything is placed in that column and row.
<div class="stack"> <div>One<div> <div>Two<div></div>
Order of Layers
You can have an unlimited number of layers in a stack
. The order of layers are determined by two factors:
- Whether they have a
background
orforeground
class - The order in which they are placed in the HTML
backgrounds
will always be placed at the bottom of the stack, while foregrounds
will always be placed at the top.
<div class="stack"> <div class="background"> Background </div> <div class="background"> Background 2 </div> <div> Content </div> <div> Content 2 </div> <div class="foreground"> Foreground </div> <div class="foreground"> Foreground 2 </div></div>
Backgrounds
background
layers let you add miscellaneous design items beyond what a standard background
property could achieve — so you can do more than just colours and gradients.
For example, you can use SVG to make beautiful backgrounds using patterns from Pattern Monster, Hero Patterns and many others.
Foregrounds
foreground
layers let you place elements before the content. This is useful for placing elements like badges, labels, or other elements that should be on top of the content.
Here’s the CSS for stack
.
The astro-island
and astro-slot
selectors help to alleviate styling frustrations when using Astro.
.stack { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); padding: 0;
&::before, &::after, > *, > *:where(.contents) > *, > *:where(astro-island, astro-slot) > * { position: relative; z-index: 1; grid-column: 1 / span 1; grid-row: 1 / span 1; }
> .background { overflow: hidden; position: absolute; inset: 0; }
> .foreground { position: relative; z-index: 10; }}
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.
Here’s the CSS for stack
.
The astro-island
and astro-slot
selectors help to alleviate styling frustrations when using Astro.
.stack { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); padding: 0;
&::before, &::after, > *, > *:where(.contents) > *, > *:where(astro-island, astro-slot) > * { position: relative; z-index: 1; grid-column: 1 / span 1; grid-row: 1 / span 1; }
> .background { overflow: hidden; position: absolute; inset: 0; }
> .foreground { position: relative; z-index: 10; }}
Stack Children
Classes
Class | Description |
---|---|
background | Background layer. |
* | Unnamed layer. Placed above background layer |
foreground | Foreground layer. Placed above other layers |
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.
Stack Children
Classes
Class | Description |
---|---|
background | Background layer. |
* | Unnamed layer. Placed above background layer |
foreground | Foreground layer. Placed above other layers |