How do you use the CSS Grid layout to create responsive web designs?

Instruction: Explain the principles of responsive design using CSS Grid, including defining grid areas and making the grid responsive.

Context: This question evaluates the candidate's expertise in using CSS Grid layout to build responsive web designs, leveraging grid areas and media queries.

Updated

Official answer available

Read the opening below, then unlock the full answer and practical guidance.

Define a narrow layout first, assign each child to a named grid area, and change tracks and areas when the content needs more room. Area names in grid-template-areas alone do not assign arbitrary children to those areas.

<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS example</title> <style> body { margin: 1rem; font: 1rem/1.5 sans-serif; } .layout { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); grid-template-areas: "header" "main" "aside" "footer"; } .layout > * { min-width: 0; overflow-wrap: anywhere; padding: 1rem; border: 1px solid; } header { grid-area: header; }...

Related Questions