SCSS Color Loop












0















I'm learning SASS/SCSS and I'm stuck in generating a color loop that outputs 5 color classes with the addition of classes darkest-lightest.
So for example I can use



class="color1 darkest"


in the end.



This is what I got so far.



<pre>
$color1: #F4858E!default;
$color1-darkest: darken( $color1, 20% )!default;
$color1-darker: darken( $color1, 10% )!default;
$color1-lighter: lighten( $color1, 10% )!default;
$color1-lightest: lighten( $color1, 20% )!default;

$color2: #BFE2CA!default;
$color2-darkest: darken( $color2, 20% )!default;
$color2-darker: darken( $color2, 10% )!default;
$color2-lighter: lighten( $color2, 10% )!default;
$color2-lightest: lighten( $color2, 20% )!default;

$color3: #A6DAEF!default;
$color3-darkest: darken( $color3, 20% )!default;
$color3-darker: darken( $color3, 10% )!default;
$color3-lighter: lighten( $color3, 10% )!default;
$color3-lightest: lighten( $color3, 20% )!default;

$color4: #FED88F!default;
$color4-darkest: darken( $color4, 20% )!default;
$color4-darker: darken( $color4, 10% )!default;
$color4-lighter: lighten( $color4, 10% )!default;
$color4-lightest: lighten( $color4, 20% )!default;

$color5: #D1B6F7!default;
$color5-darkest: darken( $color5, 20% )!default;
$color5-darker: darken( $color5, 10% )!default;
$color5-lighter: lighten( $color5, 10% )!default;
$color5-lightest: lighten( $color5, 20% )!default;


$colors: $color1, $color2, $color3, $color4, $color5;

@for $i from 1 through length($colors) {
.color#{$i} {
color: ($colors, $i);
&.darkest {
color: ($colors, $i)-darkest;
}
&.darker {
color: ($colors, $i)-darker;
}
&.lighter {
color: ($colors, $i)-lighter;
}
&.lightest {
color: ($colors, $i)-lightest;
}

}
}
</pre>


The output is pretty wrong at the moment...
Thanks for your help in advance!










share|improve this question























  • Do you need, for example, the $color3-lightest variable also in another point of your code or only in that loop? I mean, do you have to create all those variables or did you just do it for your list&loops?

    – ReSedano
    Nov 26 '18 at 14:18











  • i also would remove all variables with $color-something and create the colors on the fly in your loop

    – Dirk
    Nov 26 '18 at 15:23











  • @ReSedano I need both. For use in SASS (for predefined Elements) as well as classes (for flexible elements in HTML).

    – Mike
    Nov 28 '18 at 10:49











  • @Dirk the question is: how? :)

    – Mike
    Nov 28 '18 at 10:49
















0















I'm learning SASS/SCSS and I'm stuck in generating a color loop that outputs 5 color classes with the addition of classes darkest-lightest.
So for example I can use



class="color1 darkest"


in the end.



This is what I got so far.



<pre>
$color1: #F4858E!default;
$color1-darkest: darken( $color1, 20% )!default;
$color1-darker: darken( $color1, 10% )!default;
$color1-lighter: lighten( $color1, 10% )!default;
$color1-lightest: lighten( $color1, 20% )!default;

$color2: #BFE2CA!default;
$color2-darkest: darken( $color2, 20% )!default;
$color2-darker: darken( $color2, 10% )!default;
$color2-lighter: lighten( $color2, 10% )!default;
$color2-lightest: lighten( $color2, 20% )!default;

$color3: #A6DAEF!default;
$color3-darkest: darken( $color3, 20% )!default;
$color3-darker: darken( $color3, 10% )!default;
$color3-lighter: lighten( $color3, 10% )!default;
$color3-lightest: lighten( $color3, 20% )!default;

$color4: #FED88F!default;
$color4-darkest: darken( $color4, 20% )!default;
$color4-darker: darken( $color4, 10% )!default;
$color4-lighter: lighten( $color4, 10% )!default;
$color4-lightest: lighten( $color4, 20% )!default;

$color5: #D1B6F7!default;
$color5-darkest: darken( $color5, 20% )!default;
$color5-darker: darken( $color5, 10% )!default;
$color5-lighter: lighten( $color5, 10% )!default;
$color5-lightest: lighten( $color5, 20% )!default;


$colors: $color1, $color2, $color3, $color4, $color5;

@for $i from 1 through length($colors) {
.color#{$i} {
color: ($colors, $i);
&.darkest {
color: ($colors, $i)-darkest;
}
&.darker {
color: ($colors, $i)-darker;
}
&.lighter {
color: ($colors, $i)-lighter;
}
&.lightest {
color: ($colors, $i)-lightest;
}

}
}
</pre>


The output is pretty wrong at the moment...
Thanks for your help in advance!










share|improve this question























  • Do you need, for example, the $color3-lightest variable also in another point of your code or only in that loop? I mean, do you have to create all those variables or did you just do it for your list&loops?

    – ReSedano
    Nov 26 '18 at 14:18











  • i also would remove all variables with $color-something and create the colors on the fly in your loop

    – Dirk
    Nov 26 '18 at 15:23











  • @ReSedano I need both. For use in SASS (for predefined Elements) as well as classes (for flexible elements in HTML).

    – Mike
    Nov 28 '18 at 10:49











  • @Dirk the question is: how? :)

    – Mike
    Nov 28 '18 at 10:49














0












0








0








I'm learning SASS/SCSS and I'm stuck in generating a color loop that outputs 5 color classes with the addition of classes darkest-lightest.
So for example I can use



class="color1 darkest"


in the end.



This is what I got so far.



<pre>
$color1: #F4858E!default;
$color1-darkest: darken( $color1, 20% )!default;
$color1-darker: darken( $color1, 10% )!default;
$color1-lighter: lighten( $color1, 10% )!default;
$color1-lightest: lighten( $color1, 20% )!default;

$color2: #BFE2CA!default;
$color2-darkest: darken( $color2, 20% )!default;
$color2-darker: darken( $color2, 10% )!default;
$color2-lighter: lighten( $color2, 10% )!default;
$color2-lightest: lighten( $color2, 20% )!default;

$color3: #A6DAEF!default;
$color3-darkest: darken( $color3, 20% )!default;
$color3-darker: darken( $color3, 10% )!default;
$color3-lighter: lighten( $color3, 10% )!default;
$color3-lightest: lighten( $color3, 20% )!default;

$color4: #FED88F!default;
$color4-darkest: darken( $color4, 20% )!default;
$color4-darker: darken( $color4, 10% )!default;
$color4-lighter: lighten( $color4, 10% )!default;
$color4-lightest: lighten( $color4, 20% )!default;

$color5: #D1B6F7!default;
$color5-darkest: darken( $color5, 20% )!default;
$color5-darker: darken( $color5, 10% )!default;
$color5-lighter: lighten( $color5, 10% )!default;
$color5-lightest: lighten( $color5, 20% )!default;


$colors: $color1, $color2, $color3, $color4, $color5;

@for $i from 1 through length($colors) {
.color#{$i} {
color: ($colors, $i);
&.darkest {
color: ($colors, $i)-darkest;
}
&.darker {
color: ($colors, $i)-darker;
}
&.lighter {
color: ($colors, $i)-lighter;
}
&.lightest {
color: ($colors, $i)-lightest;
}

}
}
</pre>


The output is pretty wrong at the moment...
Thanks for your help in advance!










share|improve this question














I'm learning SASS/SCSS and I'm stuck in generating a color loop that outputs 5 color classes with the addition of classes darkest-lightest.
So for example I can use



class="color1 darkest"


in the end.



This is what I got so far.



<pre>
$color1: #F4858E!default;
$color1-darkest: darken( $color1, 20% )!default;
$color1-darker: darken( $color1, 10% )!default;
$color1-lighter: lighten( $color1, 10% )!default;
$color1-lightest: lighten( $color1, 20% )!default;

$color2: #BFE2CA!default;
$color2-darkest: darken( $color2, 20% )!default;
$color2-darker: darken( $color2, 10% )!default;
$color2-lighter: lighten( $color2, 10% )!default;
$color2-lightest: lighten( $color2, 20% )!default;

$color3: #A6DAEF!default;
$color3-darkest: darken( $color3, 20% )!default;
$color3-darker: darken( $color3, 10% )!default;
$color3-lighter: lighten( $color3, 10% )!default;
$color3-lightest: lighten( $color3, 20% )!default;

$color4: #FED88F!default;
$color4-darkest: darken( $color4, 20% )!default;
$color4-darker: darken( $color4, 10% )!default;
$color4-lighter: lighten( $color4, 10% )!default;
$color4-lightest: lighten( $color4, 20% )!default;

$color5: #D1B6F7!default;
$color5-darkest: darken( $color5, 20% )!default;
$color5-darker: darken( $color5, 10% )!default;
$color5-lighter: lighten( $color5, 10% )!default;
$color5-lightest: lighten( $color5, 20% )!default;


$colors: $color1, $color2, $color3, $color4, $color5;

@for $i from 1 through length($colors) {
.color#{$i} {
color: ($colors, $i);
&.darkest {
color: ($colors, $i)-darkest;
}
&.darker {
color: ($colors, $i)-darker;
}
&.lighter {
color: ($colors, $i)-lighter;
}
&.lightest {
color: ($colors, $i)-lightest;
}

}
}
</pre>


The output is pretty wrong at the moment...
Thanks for your help in advance!







loops colors sass






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 26 '18 at 10:14









MikeMike

34




34













  • Do you need, for example, the $color3-lightest variable also in another point of your code or only in that loop? I mean, do you have to create all those variables or did you just do it for your list&loops?

    – ReSedano
    Nov 26 '18 at 14:18











  • i also would remove all variables with $color-something and create the colors on the fly in your loop

    – Dirk
    Nov 26 '18 at 15:23











  • @ReSedano I need both. For use in SASS (for predefined Elements) as well as classes (for flexible elements in HTML).

    – Mike
    Nov 28 '18 at 10:49











  • @Dirk the question is: how? :)

    – Mike
    Nov 28 '18 at 10:49



















  • Do you need, for example, the $color3-lightest variable also in another point of your code or only in that loop? I mean, do you have to create all those variables or did you just do it for your list&loops?

    – ReSedano
    Nov 26 '18 at 14:18











  • i also would remove all variables with $color-something and create the colors on the fly in your loop

    – Dirk
    Nov 26 '18 at 15:23











  • @ReSedano I need both. For use in SASS (for predefined Elements) as well as classes (for flexible elements in HTML).

    – Mike
    Nov 28 '18 at 10:49











  • @Dirk the question is: how? :)

    – Mike
    Nov 28 '18 at 10:49

















Do you need, for example, the $color3-lightest variable also in another point of your code or only in that loop? I mean, do you have to create all those variables or did you just do it for your list&loops?

– ReSedano
Nov 26 '18 at 14:18





Do you need, for example, the $color3-lightest variable also in another point of your code or only in that loop? I mean, do you have to create all those variables or did you just do it for your list&loops?

– ReSedano
Nov 26 '18 at 14:18













i also would remove all variables with $color-something and create the colors on the fly in your loop

– Dirk
Nov 26 '18 at 15:23





i also would remove all variables with $color-something and create the colors on the fly in your loop

– Dirk
Nov 26 '18 at 15:23













@ReSedano I need both. For use in SASS (for predefined Elements) as well as classes (for flexible elements in HTML).

– Mike
Nov 28 '18 at 10:49





@ReSedano I need both. For use in SASS (for predefined Elements) as well as classes (for flexible elements in HTML).

– Mike
Nov 28 '18 at 10:49













@Dirk the question is: how? :)

– Mike
Nov 28 '18 at 10:49





@Dirk the question is: how? :)

– Mike
Nov 28 '18 at 10:49












1 Answer
1






active

oldest

votes


















0














just like this



// scss
$color1: #F4858E;
$color2: #BFE2CA;
$color3: #A6DAEF;
$color4: #FED88F;
$color5: #D1B6F7;

$colors: $color1, $color2, $color3, $color4, $color5;

@for $i from 1 through length($colors) {
.color#{$i} {
color: nth($colors, $i);
&.darkest {
color: darken(nth($colors, $i), 20%);
}
&.darker {
color: darken(nth($colors, $i), 10%);
}
&.lighter {
color: lighten(nth($colors, $i), 10%);
}
&.lightest {
color: lighten(nth($colors, $i), 20%);
}
}
}


gives me that output



//css
.color1 {
color: #F4858E;
}
.color1.darkest {
color: #ec2737;
}
.color1.darker {
color: #f05663;
}
.color1.lighter {
color: #f8b4b9;
}
.color1.lightest {
color: #fce3e5;
}

.color2 {
color: #BFE2CA;
}
.color2.darkest {
color: #79c290;
}
.color2.darker {
color: #9cd2ad;
}
.color2.lighter {
color: #e2f2e7;
}
.color2.lightest {
color: white;
}

.color3 {
color: #A6DAEF;
}
.color3.darkest {
color: #50b6df;
}
.color3.darker {
color: #7bc8e7;
}
.color3.lighter {
color: #d1ecf7;
}
.color3.lightest {
color: #fcfeff;
}

.color4 {
color: #FED88F;
}
.color4.darkest {
color: #fdb52a;
}
.color4.darker {
color: #fec65c;
}
.color4.lighter {
color: #feeac2;
}
.color4.lightest {
color: #fffbf4;
}

.color5 {
color: #D1B6F7;
}
.color5.darkest {
color: #975aed;
}
.color5.darker {
color: #b488f2;
}
.color5.lighter {
color: #eee4fc;
}
.color5.lightest {
color: white;
}


is that what you want ?






share|improve this answer
























  • Sorry for the late reply. Yes, this works. Thank you very much!

    – Mike
    Jan 28 at 13:58












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53478911%2fscss-color-loop%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














just like this



// scss
$color1: #F4858E;
$color2: #BFE2CA;
$color3: #A6DAEF;
$color4: #FED88F;
$color5: #D1B6F7;

$colors: $color1, $color2, $color3, $color4, $color5;

@for $i from 1 through length($colors) {
.color#{$i} {
color: nth($colors, $i);
&.darkest {
color: darken(nth($colors, $i), 20%);
}
&.darker {
color: darken(nth($colors, $i), 10%);
}
&.lighter {
color: lighten(nth($colors, $i), 10%);
}
&.lightest {
color: lighten(nth($colors, $i), 20%);
}
}
}


gives me that output



//css
.color1 {
color: #F4858E;
}
.color1.darkest {
color: #ec2737;
}
.color1.darker {
color: #f05663;
}
.color1.lighter {
color: #f8b4b9;
}
.color1.lightest {
color: #fce3e5;
}

.color2 {
color: #BFE2CA;
}
.color2.darkest {
color: #79c290;
}
.color2.darker {
color: #9cd2ad;
}
.color2.lighter {
color: #e2f2e7;
}
.color2.lightest {
color: white;
}

.color3 {
color: #A6DAEF;
}
.color3.darkest {
color: #50b6df;
}
.color3.darker {
color: #7bc8e7;
}
.color3.lighter {
color: #d1ecf7;
}
.color3.lightest {
color: #fcfeff;
}

.color4 {
color: #FED88F;
}
.color4.darkest {
color: #fdb52a;
}
.color4.darker {
color: #fec65c;
}
.color4.lighter {
color: #feeac2;
}
.color4.lightest {
color: #fffbf4;
}

.color5 {
color: #D1B6F7;
}
.color5.darkest {
color: #975aed;
}
.color5.darker {
color: #b488f2;
}
.color5.lighter {
color: #eee4fc;
}
.color5.lightest {
color: white;
}


is that what you want ?






share|improve this answer
























  • Sorry for the late reply. Yes, this works. Thank you very much!

    – Mike
    Jan 28 at 13:58
















0














just like this



// scss
$color1: #F4858E;
$color2: #BFE2CA;
$color3: #A6DAEF;
$color4: #FED88F;
$color5: #D1B6F7;

$colors: $color1, $color2, $color3, $color4, $color5;

@for $i from 1 through length($colors) {
.color#{$i} {
color: nth($colors, $i);
&.darkest {
color: darken(nth($colors, $i), 20%);
}
&.darker {
color: darken(nth($colors, $i), 10%);
}
&.lighter {
color: lighten(nth($colors, $i), 10%);
}
&.lightest {
color: lighten(nth($colors, $i), 20%);
}
}
}


gives me that output



//css
.color1 {
color: #F4858E;
}
.color1.darkest {
color: #ec2737;
}
.color1.darker {
color: #f05663;
}
.color1.lighter {
color: #f8b4b9;
}
.color1.lightest {
color: #fce3e5;
}

.color2 {
color: #BFE2CA;
}
.color2.darkest {
color: #79c290;
}
.color2.darker {
color: #9cd2ad;
}
.color2.lighter {
color: #e2f2e7;
}
.color2.lightest {
color: white;
}

.color3 {
color: #A6DAEF;
}
.color3.darkest {
color: #50b6df;
}
.color3.darker {
color: #7bc8e7;
}
.color3.lighter {
color: #d1ecf7;
}
.color3.lightest {
color: #fcfeff;
}

.color4 {
color: #FED88F;
}
.color4.darkest {
color: #fdb52a;
}
.color4.darker {
color: #fec65c;
}
.color4.lighter {
color: #feeac2;
}
.color4.lightest {
color: #fffbf4;
}

.color5 {
color: #D1B6F7;
}
.color5.darkest {
color: #975aed;
}
.color5.darker {
color: #b488f2;
}
.color5.lighter {
color: #eee4fc;
}
.color5.lightest {
color: white;
}


is that what you want ?






share|improve this answer
























  • Sorry for the late reply. Yes, this works. Thank you very much!

    – Mike
    Jan 28 at 13:58














0












0








0







just like this



// scss
$color1: #F4858E;
$color2: #BFE2CA;
$color3: #A6DAEF;
$color4: #FED88F;
$color5: #D1B6F7;

$colors: $color1, $color2, $color3, $color4, $color5;

@for $i from 1 through length($colors) {
.color#{$i} {
color: nth($colors, $i);
&.darkest {
color: darken(nth($colors, $i), 20%);
}
&.darker {
color: darken(nth($colors, $i), 10%);
}
&.lighter {
color: lighten(nth($colors, $i), 10%);
}
&.lightest {
color: lighten(nth($colors, $i), 20%);
}
}
}


gives me that output



//css
.color1 {
color: #F4858E;
}
.color1.darkest {
color: #ec2737;
}
.color1.darker {
color: #f05663;
}
.color1.lighter {
color: #f8b4b9;
}
.color1.lightest {
color: #fce3e5;
}

.color2 {
color: #BFE2CA;
}
.color2.darkest {
color: #79c290;
}
.color2.darker {
color: #9cd2ad;
}
.color2.lighter {
color: #e2f2e7;
}
.color2.lightest {
color: white;
}

.color3 {
color: #A6DAEF;
}
.color3.darkest {
color: #50b6df;
}
.color3.darker {
color: #7bc8e7;
}
.color3.lighter {
color: #d1ecf7;
}
.color3.lightest {
color: #fcfeff;
}

.color4 {
color: #FED88F;
}
.color4.darkest {
color: #fdb52a;
}
.color4.darker {
color: #fec65c;
}
.color4.lighter {
color: #feeac2;
}
.color4.lightest {
color: #fffbf4;
}

.color5 {
color: #D1B6F7;
}
.color5.darkest {
color: #975aed;
}
.color5.darker {
color: #b488f2;
}
.color5.lighter {
color: #eee4fc;
}
.color5.lightest {
color: white;
}


is that what you want ?






share|improve this answer













just like this



// scss
$color1: #F4858E;
$color2: #BFE2CA;
$color3: #A6DAEF;
$color4: #FED88F;
$color5: #D1B6F7;

$colors: $color1, $color2, $color3, $color4, $color5;

@for $i from 1 through length($colors) {
.color#{$i} {
color: nth($colors, $i);
&.darkest {
color: darken(nth($colors, $i), 20%);
}
&.darker {
color: darken(nth($colors, $i), 10%);
}
&.lighter {
color: lighten(nth($colors, $i), 10%);
}
&.lightest {
color: lighten(nth($colors, $i), 20%);
}
}
}


gives me that output



//css
.color1 {
color: #F4858E;
}
.color1.darkest {
color: #ec2737;
}
.color1.darker {
color: #f05663;
}
.color1.lighter {
color: #f8b4b9;
}
.color1.lightest {
color: #fce3e5;
}

.color2 {
color: #BFE2CA;
}
.color2.darkest {
color: #79c290;
}
.color2.darker {
color: #9cd2ad;
}
.color2.lighter {
color: #e2f2e7;
}
.color2.lightest {
color: white;
}

.color3 {
color: #A6DAEF;
}
.color3.darkest {
color: #50b6df;
}
.color3.darker {
color: #7bc8e7;
}
.color3.lighter {
color: #d1ecf7;
}
.color3.lightest {
color: #fcfeff;
}

.color4 {
color: #FED88F;
}
.color4.darkest {
color: #fdb52a;
}
.color4.darker {
color: #fec65c;
}
.color4.lighter {
color: #feeac2;
}
.color4.lightest {
color: #fffbf4;
}

.color5 {
color: #D1B6F7;
}
.color5.darkest {
color: #975aed;
}
.color5.darker {
color: #b488f2;
}
.color5.lighter {
color: #eee4fc;
}
.color5.lightest {
color: white;
}


is that what you want ?







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 28 '18 at 13:52









DirkDirk

721413




721413













  • Sorry for the late reply. Yes, this works. Thank you very much!

    – Mike
    Jan 28 at 13:58



















  • Sorry for the late reply. Yes, this works. Thank you very much!

    – Mike
    Jan 28 at 13:58

















Sorry for the late reply. Yes, this works. Thank you very much!

– Mike
Jan 28 at 13:58





Sorry for the late reply. Yes, this works. Thank you very much!

– Mike
Jan 28 at 13:58




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53478911%2fscss-color-loop%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen