Stacks
Stacks provide a 3 dimensional effect to your content. This can be helpful for displaying lots of notifications or other content in a small space.
Basic Stack
A Stack is a wrapper around other elements, making its children appear on top of each other.
This example uses a slightly transparent background and some clever padding to show the effect.
- card_css = "bg-base-100/80 border-base-300 border shadow-lg text-center"
= daisy_stack do
= daisy_card(css: card_css + " pb-2") do
Top Stack
= daisy_card(css: card_css + " py-1") do
Middle Stack
= daisy_card(css: card_css + " pt-2") do
Bottom Stack
Animated Stack
You can also do some slick effects with a library like Anime.js!
Click to remove and see the cards underneath.
Click to remove and see the cards underneath.
%div
%p.my-4
Click to remove and see the cards underneath.
.flex.justify-center.items-center
- card_css = "border-base-300 border shadow-lg cursor-pointer text-center transition-transform"
- card_html = { onclick: "(function(el) { anime({ targets: el, duration: 400, easing: \"easeInQuad\", translateY: \"-100%\", opacity: 0, complete: function() { el.remove() } }) })(this)" }
= daisy_stack do
= daisy_card(css: card_css + " bg-primary text-white", html: card_html) do
Stack 1
= daisy_card(css: card_css + " bg-secondary text-white", html: card_html) do
Stack 2
= daisy_card(css: card_css + " bg-accent text-white", html: card_html) do
Stack 3
= daisy_card(css: card_css + " bg-neutral text-neutral-content cursor-default!") do
Can't Remove Me!
Stack Positions
DaisyUI 5 introduces directional stacking with stack-top, stack-bottom, stack-start,
and stack-end CSS classes. These allow you to position the stacked elements in
different directions.
stack-top
stack-bottom
stack-start
stack-end
stack-top
stack-bottom
stack-start
stack-end
.grid.grid-cols-2.gap-6
.space-y-2
%p.font-medium.text-center stack-top
= daisy_stack(css: "stack-top size-28") do
- card_css = "border-base-300 border shadow-lg text-center flex items-center justify-center"
= daisy_card(css: card_css + " bg-primary text-white") do
1
= daisy_card(css: card_css + " bg-secondary text-white") do
2
= daisy_card(css: card_css + " bg-accent text-white") do
3
.space-y-2
%p.font-medium.text-center stack-bottom
= daisy_stack(css: "stack-bottom size-28") do
- card_css = "border-base-300 border shadow-lg text-center flex items-center justify-center"
= daisy_card(css: card_css + " bg-primary text-white") do
1
= daisy_card(css: card_css + " bg-secondary text-white") do
2
= daisy_card(css: card_css + " bg-accent text-white") do
3
.space-y-2
%p.font-medium.text-center stack-start
= daisy_stack(css: "stack-start size-28") do
- card_css = "border-base-300 border shadow-lg text-center flex items-center justify-center"
= daisy_card(css: card_css + " bg-primary text-white") do
1
= daisy_card(css: card_css + " bg-secondary text-white") do
2
= daisy_card(css: card_css + " bg-accent text-white") do
3
.space-y-2
%p.font-medium.text-center stack-end
= daisy_stack(css: "stack-end size-28") do
- card_css = "border-base-300 border shadow-lg text-center flex items-center justify-center"
= daisy_card(css: card_css + " bg-primary text-white") do
1
= daisy_card(css: card_css + " bg-secondary text-white") do
2
= daisy_card(css: card_css + " bg-accent text-white") do
3
CSS Stack
The Stack component simply applies the stack CSS class, which you can
also use directly.
You can also add spacing between stacked elements using gap utilities like
gap-3. Adjust the slider below to see how different gap values affect
the stack.
.space-y-4{ data: { controller: "stack-gap" } }
.flex.flex-wrap.items-center.gap-4
%span.text-sm.min-w-16 Gap size:
= daisy_badge("3", css: "badge-primary", data: { stack_gap_target: "label" })
= daisy_range(min: 1, max: 5, value: 3, css: "range-primary", data: { stack_gap_target: "slider", action: "input->stack-gap#updateGap" })
- # Raw `.stack` on purpose: this example demonstrates using the CSS class
- # directly, as the description says, rather than the helper.
-# haml-lint:disable LocoMotionComponentUsage
.stack.gap-3.w-full.max-w-96{ data: { stack_gap_target: "stack" } }
%img{ src: image_path("landscapes/beach.jpg") }
%img{ src: image_path("landscapes/desert.jpg") }
%img{ src: image_path("landscapes/forest.jpg") }