How do you use CSS Variables within media queries to create a responsive design?
Instruction: Explain the process and benefits of using CSS Variables within media queries.
Context: This question evaluates the candidate's knowledge in leveraging CSS Variables within media queries to craft responsive designs efficiently.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
Set custom properties inside matching media-query rules and use them in ordinary declarations. The cascade chooses the values; elements that inherit or declare those properties then use them through var().
<!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> :root { --space: 8px; --columns: 1; } .cards { display: grid; grid-template-columns: repeat(var(--columns), minmax(0, 1fr)); gap:...