Using Functions with Parameters in Sass
📖 Scenario: You are creating a simple style for buttons on a website. You want to use a Sass function to calculate the padding size based on a base size and a multiplier. This helps keep your styles consistent and easy to update.
🎯 Goal: Build a Sass function called calculate-padding that takes two parameters: $base and $multiplier. Use this function to set the padding of a button with a base size of 0.5rem and a multiplier of 3.
📋 What You'll Learn
Create a Sass function named
calculate-padding with parameters $base and $multiplier.Inside the function, return the product of
$base and $multiplier.Use the
calculate-padding function to set the padding of a .button class.Set the base padding size to
0.5rem and the multiplier to 3 when calling the function.Ensure the Sass code compiles to valid CSS that styles the button's padding correctly.
💡 Why This Matters
🌍 Real World
Using functions in Sass helps keep styles consistent and easy to update across a website, especially for spacing and sizing.
💼 Career
Knowing how to write and use Sass functions is valuable for front-end developers to write maintainable and scalable CSS.
Progress0 / 4 steps