Using Default Parameter Values in Sass Mixins
📖 Scenario: You are creating a simple style for buttons on a website. You want to use a Sass mixin to style buttons with colors, but sometimes you want to use default colors if no specific colors are given.
🎯 Goal: Build a Sass mixin called button-style that uses default parameter values for $bg-color and $text-color. Then apply this mixin to two button classes: one uses default colors, and the other uses custom colors.
📋 What You'll Learn
Create a Sass mixin named
button-style with two parameters: $bg-color defaulting to #3498db and $text-color defaulting to #ffffff.Inside the mixin, set
background-color to $bg-color and color to $text-color.Create a CSS class
.btn-default that uses the button-style mixin without passing any arguments.Create a CSS class
.btn-custom that uses the button-style mixin with $bg-color set to #e74c3c and $text-color set to #000000.💡 Why This Matters
🌍 Real World
Using default parameters in Sass mixins helps developers create reusable and flexible styles for websites, saving time and reducing repeated code.
💼 Career
Front-end developers often use Sass to write maintainable CSS. Knowing how to use default parameters in mixins is a common skill required in web development jobs.
Progress0 / 4 steps