Using Mixins with @include in Sass
📖 Scenario: You are creating a simple webpage style where multiple buttons share common styles. To avoid repeating code, you will use a Sass mixin and include it in different button classes.
🎯 Goal: Build a Sass stylesheet that defines a mixin called button-style with specific styles, then include this mixin in two button classes: .primary-button and .secondary-button.
📋 What You'll Learn
Create a mixin named
button-style that sets padding to 1rem 2rem, border-radius to 0.5rem, and font-weight to bold.Create a class
.primary-button that includes the button-style mixin and sets background-color to #007bff and color to white.Create a class
.secondary-button that includes the button-style mixin and sets background-color to #6c757d and color to white.Use the
@include directive to include the mixin inside the button classes.💡 Why This Matters
🌍 Real World
Mixins help keep CSS code clean and reusable, especially when many elements share similar styles like buttons.
💼 Career
Knowing how to use Sass mixins is valuable for front-end developers to write maintainable and scalable stylesheets.
Progress0 / 4 steps