Card component is a versatile layout component that provides a styled container with support for responsive grid positioning. It can be used as a standalone content card or as a clickable link card.
Props
The title text displayed at the top of the card
The body text content of the card
CSS classes to control the card’s column span in a grid layout. Use Tailwind grid column classes to define responsive widths.Common values:
lg:col-span-9 md:col-span-2- Large span on desktop, medium on tabletlg:col-span-3 md:col-span-1- Small span across breakpointsmd:col-span-6 lg:col-span-6- Half width on medium and large screens
CSS classes to control the card’s row span in a grid layout. Use Tailwind grid row classes to define card height.Common values:
md:row-span-1 lg:row-span-4- Different heights at different breakpointsmd:row-span-3 lg:row-span-8- Taller cardmd:row-span-2 lg:row-span-2- Medium height card
URL for the card to link to. When provided, the entire card becomes clickable and displays an arrow icon on hover.
CSS classes to customize the text color when the card is used as a link
Usage
Basic Card
Card with Custom Content
Link Card with href
Grid Layout Example
The Card component works best within a CSS Grid layout. Here’s how cards are used in the portfolio template:Features
- Responsive Grid Support: Use
colSpanandrowSpanprops to control card positioning across breakpoints - Optional Link Behavior: Add an
hrefprop to make the entire card clickable - Hover Effects: Cards with links display a hover state with border color change and arrow icon
- Flexible Content: Use the default slot to insert any custom content
- Built on shadcn/ui: Leverages the shadcn Card component for consistent styling
- Animation Ready: Includes
card-animateclass for integration with animation libraries
Component Source
Location:src/components/Card.astro