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.