As @hopper has said the main problem is that you haven't prefixed interpolated variables with a dollar sign so his answer should be marked as the correct, but I want to add a tip.
Use @each
rule instead of @for
loop for this specific case. The reasons:
- You don't need to know the length of the list
- You don't need to use
length()
function to calculate the length of the list
- You don't need to use nth() function
@each
rule is more semantic than @for
directive
The code:
$colours: rgb(255,255,255), // white
rgb(255,0,0), // red
rgb(135,206,250), // sky blue
rgb(255,255,0); // yellow
@each $colour in $colours {
#cp#{$colour} {
background-color: rgba($colour, 0.6);
&:hover {
background-color: rgba($colour, 1);
cursor: pointer;
}
}
}
Or if you prefer you can include each $colour in the @each directive instead of declare $colors variable:
$colour1: rgb(255,255,255); // white
$colour2: rgb(255,0,0); // red
$colour3: rgb(135,206,250); // sky blue
$colour4: rgb(255,255,0); // yellow
@each $colour in $colour1, $colour2, $colour3, $colour4 {
#cp#{$colour} {
background-color: rgba($colour, 0.6);
&:hover {
background-color: rgba($colour, 1);
cursor: pointer;
}
}
}
Sass Reference for @each
directive