02. Card Layout Components & Elevation Shadows
🟢 Beginner
1. Definition
Card Components encapsulate related media, titles, text descriptions, and action buttons into self-contained container blocks with subtle border radius, padding, and elevation box-shadow transitions.
2. Why It Is Used
Cards create structured visual chunks that make web content easily scannable on e-commerce, dashboard, and portfolio websites.
3. How It Works
Cards use display: flex or display: grid internally to structure header images, body text, and footers while layering box-shadow for 3D depth elevation.
4. Syntax
.ui-card {
background: white;
border-radius: 12px;
overflow: hidden;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
transition: transform 0.2s, box-shadow 0.2s;
}
5. Card Types Reference Table
| Card Type | Internal Layout | Best Practice Usage |
|---|---|---|
| Media Card | Stacked image top + text body bottom | Blog posts & product listings |
| Metric Card | Flex row icon left + metric number right | Dashboard analytics widgets |
| Interactive Card | Hover lift with transform: translateY(-4px) | Clickable portfolio items |
6. Beginner Example
.simple-card {
background: white;
padding: 20px;
border-radius: 8px;
border: 1px solid #e2e8f0;
}
7. Intermediate Example
.product-card {
border-radius: 12px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
transition: transform 0.2s, box-shadow 0.2s;
}
.product-card:hover {
transform: translateY(-4px);
box-shadow: 0 12px 20px rgba(0, 0, 0, 0.1);
}
8. Advanced Subgrid Card Component Example
.card-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 24px;
}
.card {
display: grid;
grid-row: span 3;
grid-template-rows: subgrid;
background: white;
border-radius: 12px;
overflow: hidden;
}
9. Line-by-Line Code Explanation
grid-template-rows: subgrid;: Ensures card headers, bodies, and footers align across all cards in a grid row regardless of content height differences.
10. Expected Terminal / Browser Output
A clean grid of interactive cards that lift smoothly when hovered with perfectly aligned button footers.
11. Common Mistakes & Pitfalls
- Forgetting
overflow: hiddenon rounded cards with header images: Withoutoverflow: hidden, image corners overflow past the card'sborder-radius.
12. Important Rules & Limitations
- Always set
overflow: hiddenon cards containing top hero images.
13. Multilingual Explanation: English
Card components group related UI content. Use box-shadow and border-radius for clean elevation.
14. Multilingual Explanation: Hindi (Roman Script)
Card components content ko clean box mein wrap karte hain. Hover lift ke liye transform: translateY(-4px) use karein.
15. Multilingual Explanation: Marathi (Roman Script)
Cards mule content structured diste. Hover elevation sathi box-shadow vapara.
16. Practice Questions
- Why is
overflow: hiddenrequired on cards with top background images?
17. Practical Coding Challenge
Build a .hover-card rule that transitions box-shadow and transform on hover.