Search code examples
sassnode-sass

Mix Gardiant and a value together


I have a value in Sass with $mainColor:#070517; I want to know what is the best way to put this Gardiant script instead of that color?

background: -webkit-linear-gradient(to top, #24243e, #302b63, #0f0c29);  /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to top, #24243e, #302b63, #0f0c29); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */```


Solution

  • You can add a mixin

    @mixin my-gradient {
    background: -webkit-linear-gradient(to top, #24243e, #302b63, #0f0c29);
    background: linear-gradient(to top, #24243e, #302b63, #0f0c29);
    }
    
    div {
    @include my-gradient;
    }