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.
A Stack is a wrapper around other elements, making it's children appear on top of each other.
This example uses a slightly transparent background and some clever padding to show the effect.
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!
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
.stack.stack-top.size-28
- 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
.stack.stack-bottom.size-28
- 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
.stack.stack-start.size-28
- 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
.stack.stack-end.size-28
- 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
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.items-center.gap-4
%span.text-sm.min-w-16 Gap size:
%span.badge.badge-primary{ data: { stack_gap_target: "label" } } 3
%input.range.range-primary{
type: "range",
min: "1",
max: "5",
value: "3",
data: { stack_gap_target: "slider", action: "input->stack-gap#updateGap" }
}
.stack.w-96{ data: { stack_gap_target: "stack", class: "gap-3" } }
%img{ src: image_path("landscapes/beach.jpg") }
%img{ src: image_path("landscapes/desert.jpg") }
%img{ src: image_path("landscapes/forest.jpg") }
Create virtual credit / debit cards to keep your real info safe.
Get $5 when you sign up — free to start!
Everything you need to grow your business with confidence!
CRM, Lead Generation, Project Management, Contracts, Online Payments, and more!
The ads above are affiliate links to products I regularly use and highly
recommend.
I may receive a commission if you decide to purchase.