Using Mixins with Parameters in Sass
📖 Scenario: You are designing a simple website and want to reuse a button style with different colors. Instead of writing the same CSS multiple times, you will use a Sass mixin with parameters to create buttons with different background colors.
🎯 Goal: Create a Sass mixin named button-style that accepts a $color parameter. Use this mixin to style two buttons with different background colors.
📋 What You'll Learn
Create a mixin named
button-style with a $color parameterThe mixin should set the background color to
$color, text color to white, padding to 1rem 2rem, and border-radius to 0.5remUse the mixin to style a button with class
.btn-primary with background color #007bffUse the mixin to style a button with class
.btn-success with background color #28a745💡 Why This Matters
🌍 Real World
Mixins with parameters are used in real projects to write reusable, customizable styles that save time and reduce errors.
💼 Career
Knowing how to write and use Sass mixins with parameters is a valuable skill for front-end developers working on scalable CSS codebases.
Progress0 / 4 steps