9.4 Homework/Practice
Create a Two-Column Responsive Layout Using Flexbox
Step 1:
Create an HTML file (
responsive-layout.html) with a simple two-column layout using Flexbox.<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Two-Column Layout</title> <style> body { font-family: Arial, sans-serif; margin: 0; padding: 0; } .flex-container { display: flex; flex-direction: column; gap: 20px; padding: 20px; } .flex-column-1{ flex: 1; padding: 20px; background-color: #f4f4f4; } .flex-column-2{ flex: 1; padding: 20px; background-color: ##d50b0b color:#d1d55b } @media screen and (min-width: 768px) { .flex-container { flex-direction: row; } } </style> </head> <body> <div class="flex-container"> <div class="flex-column-1">Column 1</div> <div class="flex-column-2">Column 2</div> </div> </body> </html>
Step 2:
Flexbox Layout: The two columns stack on top of each other on small screens and display side-by-side on larger screens (using a media query at
768px).
Step 3:
Responsive Behavior: Test the layout on different screen sizes (desktop, tablet, mobile). The columns should stack vertically on smaller screens and align horizontally on larger screens.
Challenge:
Add a third column for larger screens using Flexbox. Ensure that it stacks properly on smaller devices.
This lesson will give students hands-on experience building flexible and responsive layouts using Flexbox and media queries, empowering them to create designs that work across various screen sizes and devices.
Last updated