} } /* Desktop layout */ @media (min-width: 900px) { .container { grid-template-columns: 1fr 3fr; grid-template-areas: "sidebar header" "sidebar main" "sidebar footer"; } }

Responsive Design Challenges

Test your understanding of responsive design with these challenges. Click the buttons to check your knowledge!

Challenge 1: Create a mobile-first layout where content is stacked vertically on mobile and then changes to a two-column layout on desktop.
✅ Challenge complete! You've created a mobile-first layout that adapts to larger screens.
Challenge 2: Hide the sidebar on mobile devices and show it on larger screens.
✅ Challenge complete! The sidebar is hidden on mobile and visible on larger screens.
Challenge 3: Arrange the flex items in a row on desktop, but stack them vertically on mobile.
✅ Challenge complete! The flex items are correctly arranged based on screen size.
CSS Responsive Layout Interactive Exercise

CSS Responsive Layout Interactive Exercise

Instructions

Use the controls below to experiment with responsive layouts. Adjust the viewport size and see how different layout techniques adapt to various screen sizes!

Responsive design is a crucial concept in modern web development that ensures your websites look good on all devices. Key techniques include:

Layout Controls

600px
900px
Preview
320 x 480
Header
Mobile
Tablet
Desktop
Sidebar
Main Content
Item 1
Item 2
Item 3
/* Base layout */
.container {
  display: grid;
  gap: 10px;
}

/* Mobile layout (default) */
.container {
  grid-template-columns: 1fr;
  grid-template-areas: "header"
                                       "sidebar"
                                       "main"
                                       "footer";
}

/* Tablet layout */
@media (min-width: 600px) {
  .container {
    grid-template-columns: 2fr 1fr;
    grid-template-areas: "header header"
                                         "main sidebar"
                                         "footer footer";
  }