Progressive Enhancement: Start with basic layouts, enhance with
modern features
Performance Considerations
Grid and Flexbox are hardware accelerated
Avoid excessive nesting
Use appropriate units (fr, %, auto)
Minimize layout recalculations
Test on mobile devices
/* Good: Use fr units for flexible layouts */
grid-template-columns: 1fr 2fr 1fr;
/* Avoid: Fixed pixel values for responsive layouts */
grid-template-columns: 200px 400px 200px;
Accessibility Best Practices
Maintain logical document flow
Use semantic HTML elements
Ensure keyboard navigation works
Test with screen readers
Provide fallbacks for older browsers
Use appropriate ARIA attributes
Remember: Layout should enhance, not hinder, accessibility
Common Layout Patterns
Holy Grail Layout: Header, footer, sidebar, main content
Card Layout: Flexible cards in a grid
Sticky Footer: Footer at bottom of viewport
Sidebar Layout: Fixed sidebar with scrollable main
Masonry Layout: Pinterest-style grid
Dashboard: Multiple widgets in grid
Task 1: Flexbox Layout Practice
Instructions:
Create a new HTML file called flexbox-practice.html
Build a navigation bar using Flexbox with:
Logo on the left
Navigation links in the center
User menu on the right
Create a card layout with:
3 cards in a row (responsive)
Cards with image, title, description, and button
Equal height cards
Add a footer with social media links
Make it responsive for mobile devices
Time: 45 minutes
This task will help you understand Flexbox layout and responsive
design
Break Time
15 Minutes
Take a break, ask questions, or catch up on the previous task.
Next: Secondary slides and Task 2
Grid Best Practices
Plan your grid structure before coding
Use semantic names for grid areas
Keep grid definitions simple
Use appropriate units (fr, %, auto)
Test on different screen sizes
Consider mobile-first approach
/* Good: Named grid areas */
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
Auto-Fit vs Auto-Fill
/* Auto-fit: Creates as many columns as can fit */
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
/* Auto-fill: Creates as many columns as possible */
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));