Welcome to Part 46 of the CSS Mastery & Responsive Layouts Course. In this part, we will explore Building a Responsive Component Library.
A responsive component library is the foundation of modern design systems. By building modular, responsive, and accessible components (like cards, modal overlays, slide navigations, responsive tables, and button sets), you ensure visual consistency across all pages and platforms while dramatically speeding up your development workflows.
Chapter 224: Responsive Cards & Modals
Cards and modal overlays are essential components of modern web layouts.
✔ Structuring Responsive Cards
Use CSS Grid or Flexbox to build cards that scale gracefully across viewport sizes:
.card-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 20px;
}
.ui-card {
display: flex;
flex-direction: column;
background-color: #ffffff;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
overflow: hidden;
}
.ui-card__content {
padding: 16px;
flex-grow: 1; /* Align button actions to the card bottom */
}
☑ Building Modal Overlays
Modals require fixed centering, backdrop dimming, and viewport sizing:
.modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background-color: rgba(0, 0, 0, 0.5); /* Dim backdrop */
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
}
.modal-content {
background-color: #ffffff;
padding: 24px;
border-radius: 12px;
max-width: 500px;
width: 90%;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
}
Chapter 225: Accessible Slide Navigations
Responsive navigation elements must toggle between desktop headers and mobile side panels.
✔ Slide-Out Side Navigation
Style side drawer panels to slide on and off the viewport using CSS transitions:
.side-nav {
position: fixed;
top: 0;
left: 0;
width: 280px;
height: 100%;
background-color: #1e293b;
transform: translateX(-100%); /* Start hidden off-screen */
transition: transform 0.3s ease-in-out;
z-index: 900;
}
/* Toggle state class */
.side-nav.is-open {
transform: translateX(0); /* Slide into view */
}
Chapter 226: Responsive Tables & Button Systems
Tables are notoriously difficult to display on small screens. Standard columns will break widths or clip off-screen.
✔ Responsive Scrollable Tables
Wrap your table elements inside a scroll container to prevent page width breakages:
.table-wrapper {
width: 100%;
overflow-x: auto; /* Adds horizontal scrollbar only if table overflows */
-webkit-overflow-scrolling: touch; /* Smooth mobile scroll momentum */
}
.data-table {
width: 100%;
border-collapse: collapse;
white-space: nowrap; /* Prevent messy cell wrapping */
}
☑ Scalable Button Systems
Build buttons with consistent spacing, colors, and accessibility sizes:
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 10px 20px;
font-weight: 600;
border-radius: 6px;
transition: background-color 0.2s;
cursor: pointer;
min-height: 44px; /* complies with WCAG minimum tap target dimensions */
}
.btn--primary {
background-color: #3b82f6;
color: #ffffff;
}
.btn--primary:hover {
background-color: #2563eb;
}
Chapter 227: Library Practice & Self-Check
✔ Practice Exercises
- Exercise 1: Responsive Library Page: Combine a responsive card grid, a trigger button, an overlay modal, and a responsive table wrapper into a single HTML structure. Verify layouts scale smoothly from 320px mobile up to desktop widths.
☑ Self-Check Questions
- What layouts are ideal for card grids without hardcoded media queries?
- Answer: CSS Grid template columns using
repeat(auto-fit, minmax(min, max)).
- Answer: CSS Grid template columns using
- How can button triggers inside flex cards be aligned to the bottom of the card?
- Answer: Apply
flex-grow: 1;on the card content wrapper anddisplay: flex; flex-direction: column;on the parent card.
- Answer: Apply
- What positioning style is used to float modal backdrop overlays over all page contents?
- Answer:
position: fixed;.
- Answer:
- What is the purpose of transform: translateX(-100%); on side navs?
- Answer: It hides the navigation panel off-screen to the left of the viewport boundaries.
- How do you ensure side drawer menu animations are smooth?
- Answer: Use
transition: transform 0.3s;to utilize GPU hardware acceleration.
- Answer: Use
- Why wrap tables in a container styled with overflow-x: auto;?
- Answer: To contain the table layout width and enable horizontal scrolling on small screens instead of pushing the page body content out of bounds.
- What does white-space: nowrap; do on tables?
- Answer: It prevents cell text from wrapping to multiple rows, preserving standard column widths.
- What is the WCAG recommended minimum height for touch tap targets?
- Answer: 44px (or 48px in Android guidelines).
- What z-index configuration is best for layout structures?
- Answer: Keeping z-index values small and structured (e.g. headers 500, side-navs 900, modals 1000) inside designated stacking contexts.
- Can flex-direction: row buttons align icons alongside text?
- Answer: Yes, applying
display: inline-flex; align-items: center; gap: 8px;centers icons alongside text tags perfectly.
- Answer: Yes, applying
Discussion
Loading comments...