Complete the code to define a base button style using a SASS variable.
$btn-color: [1]; .button { background-color: $btn-color; color: white; padding: 1rem 2rem; border-radius: 0.5rem; }
The variable $btn-color is set to a hex color #3498db, which is a blue shade. This color is used as the background for the button.
Complete the code to create a SASS mixin for button variants.
@mixin button-variant($color) {
background-color: [1];
border: 2px solid $color;
color: white;
}The mixin uses the parameter $color to set the background color dynamically. Variables in SASS start with a $.
Fix the error in the code to generate button variants using the mixin.
.btn-primary {
@include button-variant([1]);
}When passing a variable to a mixin, you must use the variable name with the $ prefix, like $primary-color.
Fill both blanks to create a map of button variants and loop through them to generate styles.
$btn-variants: ( primary: [1], secondary: [2] ); @each $name, $color in $btn-variants { .btn-#{$name} { @include button-variant($color); } }
The map keys are variant names, and the values are variables holding colors. Variables must have the $ prefix.
Fill all three blanks to create a function that returns a color for a variant and use it in a style.
@function get-variant-color($variant) {
@return map-get($btn-variants, [1]);
}
.btn-alert {
background-color: get-variant-color([2]);
border-color: [3];
}The function uses the parameter $variant to get the color from the map. The class uses the string alert to get the color. The border color uses the variable $alert-color.