Danelo Danelo - 1 month ago 6
Sass (Sass) Question

dont know how to make a proper mixin for background

I am using Scss for my website.I am trying to make my code easier to read so I thought about building a mixin for my background property.I haven't used a mixin before tho..
I want to create a mixin with these properties:
background: #6441A5;
background: -webkit-linear-gradient(to left, #6441A5 , #2a0845);
background: linear-gradient(to left, #6441A5 , #2a0845);

How do I do it ?

Answer

The code you need is:

@mixin background_mixin($bg) {
    background: $bg
}

And when you need to make background eg #6441A5:

@include background_mixin(#6441A5);

Mixin is like a function (in our case named background_mixin) and you give it a parameter (in our case named $bg). Then in the block of code you want to use it you make an @include with the name of the mixin and the value that you want the parameter to get.

More information here: