Responsive Card Layout with Media Query Mixins
📖 Scenario: You are building a simple card layout for a website. The cards should look good on phones, tablets, and desktops. To make your CSS easier to manage, you will create a media query mixin in Sass. This mixin will help you write responsive styles quickly and clearly.
🎯 Goal: Create a Sass mixin called respond-to that accepts a device type (phone, tablet, or desktop) and applies the correct media query. Use this mixin to make the card background color change on different screen sizes.
📋 What You'll Learn
Create a Sass map called
breakpoints with keys phone, tablet, and desktop and their respective max-width values.Create a mixin called
respond-to that takes a $device parameter and applies a media query using the breakpoints map.Use the
respond-to mixin to change the card background color for each device type.Write semantic and clean Sass code that compiles to valid CSS.
💡 Why This Matters
🌍 Real World
Web developers often need to make websites look good on many devices. Using Sass mixins for media queries saves time and reduces mistakes.
💼 Career
Knowing how to write reusable media query mixins is a valuable skill for front-end developers working on responsive designs.
Progress0 / 4 steps