Ah, I see! The issue is that each individual card is stacking its content vertically rather than maintaining the intended layout. This likely stems from how the elements inside the card are being styled or how the CardWrapper is affecting the internal structure.
Diagnosis:
CardWrapper Impact:
When you wrap the card in CardWrapper, it might be altering the internal flexbox or grid layout of the card itself.
Flexbox/Grid Layout Inside Card:
The card's internal structure uses flexbox for layout. If the wrapper changes the context or introduces unexpected styling, it can disrupt this layout.
Block-Level Elements:
The CardWrapper might be causing the card's children to stack vertically because it's treating them as block-level elements by default.
Solution:
To ensure the card's internal layout remains intact, you need to make sure that the CardWrapper does not interfere with the card's flexbox or grid layout. Here's how you can adjust the CardWrapper and ensure the card's content remains properly aligned.
Updated CardWrapper Component:
Ensure that the CardWrapper does not disrupt the card's internal layout by using inline-block or flex instead of block. This allows the card to maintain its intended structure.
"use client";
/**
* @author: @dorian_baffier
* @description: Card Flip
* @version: 1.0.0
* @date: 2025-06-26
* @license: MIT
* @website: https://kokonutui.com
* @github: https://github.com/kokonut-labs/kokonutui
*/
import { cn } from "@/lib/utils";
import { ArrowRight, Repeat2 } from "lucide-react";
import { useState } from "react";
export interface CardFlipProps {
title?: string;
subtitle?: string;
description?: string;
features?: string[];
action_text?: string;
link?: string;
}
export default function CardFlip({
title = "Design Systems",
subtitle = "Explore the fundamentals",
description = "Dive deep into the world of modern UI/UX design.",
features = ["UI/UX", "Modern Design", "Tailwind CSS", "Kokonut UI"],
action_text = "default",
link = "https://portfolio.nx7.tech",
}: CardFlipProps) {
const [isFlipped, setIsFlipped] = useState(false);
// Updated CardWrapper to use inline-flex
const CardWrapper = ({ children }: { children: React.ReactNode }) =>
link ? (
<a href={link} target="_blank" rel="noopener noreferrer" className="inline-flex">
{children}
</a>
) : (
<div className="inline-flex">{children}</div>
);
return (
// Wrap the main card structure with CardWrapper
<CardWrapper>
<div
className="relative w-full max-w-[280px] h-[320px] group [perspective:2000px]"
onMouseEnter={() => setIsFlipped(true)}
onMouseLeave={() => setIsFlipped(false)}
>
<div
className={cn(
"relative w-full h-full",
"[transform-style:preserve-3d]",
"transition-all duration-700",
isFlipped ? "[transform:rotateY(180deg)]" : "[transform:rotateY(0deg)]"
)}
>
{/* Front of card */}
<div
className={cn(
"absolute inset-0 w-full h-full",
"[backface-visibility:hidden] [transform:rotateY(0deg)]",
"overflow-hidden rounded-2xl",
"bg-zinc-50 dark:bg-zinc-900",
"border border-zinc-200 dark:border-zinc-800/50",
"shadow-xs dark:shadow-lg",
"transition-all duration-700",
"group-hover:shadow-lg dark:group-hover:shadow-xl",
isFlipped ? "opacity-0" : "opacity-100"
)}
>
{/* Background animation content goes here (like the variations I provided) */}
<div className="relative h-full overflow-hidden bg-gradient-to-b from-zinc-100 to-white dark:from-zinc-900 dark:to-black">
{/* YOUR BACKGROUND ANIMATION CODE HERE (e.g., Variation 1, 2, etc.) */}
<div className="absolute inset-0 flex items-start justify-center pt-24">
<div className="relative w-[200px] h-[100px] flex items-center justify-center">
{[...Array(10)].map((_, i) => (
<div
key={i}
className={cn(
"absolute w-[50px] h-[50px]",
"rounded-[140px]",
// NOTE: 'scale' animation needs to be defined in tailwind.config.js
// as per the variations I provided earlier.
// If you want to use the original keyframes, you'll need the <style jsx> block or move it to config.
"animate-[scale_3s_linear_infinite]", // Using the original animation name
"opacity-0",
"shadow-[0_0_50px_rgba(255,165,0,0.5)]",
"group-hover:animate-[scale_2s_linear_infinite]"
)}
style={{
animationDelay: `${i * 0.3}s`,
}}
/>
))}
</div>
</div>
</div>
{/* Front card bottom content */}
<div className="absolute bottom-0 left-0 right-0 p-5">
<div className="flex items-center justify-between gap-3">
<div className="space-y-1.5">
<h3 className="text-lg font-semibold text-zinc-900 dark:text-white leading-snug tracking-tighter transition-all duration-500 ease-out-expo group-hover:translate-y-[-4px]">
{title}
</h3>
<p className="text-sm text-zinc-600 dark:text-zinc-200 line-clamp-2 tracking-tight transition-all duration-500 ease-out-expo group-hover:translate-y-[-4px] delay-[50ms]">
{subtitle}
</p>
</div>
<div className="relative group/icon">
<div
className={cn(
"absolute inset-[-8px] rounded-lg transition-opacity duration-300",
"bg-gradient-to-br from-orange-500/20 via-orange-500/10 to-transparent"
)}
/>
<Repeat2 className="relative z-10 w-4 h-4 text-orange-500 transition-transform duration-300 group-hover/icon:scale-110 group-hover/icon:-rotate-12" />
</div>
</div>
</div>
</div>
{/* Back of card */}
<div
className={cn(
"absolute inset-0 w-full h-full",
"[backface-visibility:hidden] [transform:rotateY(180deg)]",
"p-6 rounded-2xl",
"bg-gradient-to-b from-zinc-100 to-white dark:from-zinc-900 dark:to-black",
"border border-zinc-200 dark:border-zinc-800",
"shadow-xs dark:shadow-lg",
"flex flex-col",
"transition-all duration-700",
"group-hover:shadow-lg dark:group-hover:shadow-xl",
!isFlipped ? "opacity-0" : "opacity-100"
)}
>
<div className="flex-1 space-y-6">
<div className="space-y-2">
<h3 className="text-lg font-semibold text-zinc-900 dark:text-white leading-snug tracking-tight transition-all duration-500 ease-out-expo group-hover:translate-y-[-2px]">
{title}
</h3>
<p className="text-sm text-zinc-600 dark:text-zinc-400 tracking-tight transition-all duration-500 ease-out-expo group-hover:translate-y-[-2px] line-clamp-2">
{description}
</p>
</div>
<div className="space-y-2">
{features.map((feature, index) => (
<div
key={feature}
className="flex items-center gap-2 text-sm text-zinc-700 dark:text-zinc-300 transition-all duration-500"
style={{
transform: isFlipped ? "translateX(0)" : "translateX(-10px)",
opacity: isFlipped ? 1 : 0,
transitionDelay: `${index * 100 + 200}ms`,
}}
>
<ArrowRight className="w-3 h-3 text-orange-500" />
<span>{feature}</span>
</div>
))}
</div>
</div>
<div className="pt-6 mt-6 border-t border-zinc-200 dark:border-zinc-800">
<div
className={cn(
"group/start relative",
"flex items-center justify-between",
"p-3 -m-3 rounded-xl",
"transition-all duration-300",
"bg-gradient-to-r from-zinc-100 via-zinc-100 to-zinc-100",
"dark:from-zinc-800 dark:via-zinc-800 dark:to-zinc-800",
"hover:from-orange-500/10 hover:from-0% hover:via-orange-500/5 hover:via-100% hover:to-transparent hover:to-100%",
"dark:hover:from-orange-500/20 dark:hover:from-0% dark:hover:via-orange-500/10 dark:hover:via-100% dark:hover:to-transparent dark:hover:to-100%",
"hover:scale-[1.02] hover:cursor-pointer"
)}
>
<span className="text-sm font-medium text-zinc-900 dark:text-white transition-colors duration-300 group-hover/start:text-orange-600 dark:group-hover/start:text-orange-400">
{action_text}
</span>
<div className="relative group/icon">
<div
className={cn(
"absolute inset-[-6px] rounded-lg transition-all duration-300",
"bg-gradient-to-br from-orange-500/20 via-orange-500/10 to-transparent",
"opacity-0 group-hover/start:opacity-100 scale-90 group-hover/start:scale-100"
)}
/>
<ArrowRight className="relative z-10 w-4 h-4 text-orange-500 transition-all duration-300 group-hover/start:translate-x-0.5 group-hover/start:scale-110" />
</div>
</div>
</div>
</div>
</div>
{/* IMPORTANT: If you are using tailwind.config.js to define keyframes, */}
{/* you can remove this <style jsx> block. */}
{/* If not, keep this for the 'scale' animation to work */}
<style jsx>{`
@keyframes scale {
0% {
transform: scale(2);
opacity: 0;
box-shadow: 0px 0px 50px rgba(255, 165, 0, 0.5);
}
50% {
transform: translate(0px, -5px) scale(1);
opacity: 1;
box-shadow: 0px 8px 20px rgba(255, 165, 0, 0.5);
}
100% {
transform: translate(0px, 5px) scale(0.1);
opacity: 0;
box-shadow: 0px 10px 20px rgba(255, 165, 0, 0);
}
}
`}</style>
</div>
</CardWrapper> // Closing CardWrapper
);
}
Explanation:
CardWrapper Adjustment:
Changed block to inline-flex to ensure the wrapper doesn't disrupt the card's internal flexbox layout.
inline-flex allows the card to maintain its flexbox structure while being wrapped by the link or div.
Card Structure:
The card's internal structure uses flexbox for layout. By using inline-flex in the CardWrapper, we ensure that the card's flexbox context remains intact.
This should resolve the issue of each card becoming a single vertical line and maintain the intended layout.