I've written the following loop to loop through a list of team to generate the background position for a sprite image. How can I make this into a function so that I can pass in the $teams, $X and $Y value instead?
$teams: A, B, C, D;
$x: 0;
$y: 0;
@each $team in $teams {
$i: index($teams, $team);
$y: $y + 20px;
.team#{$team}:before,
.team#{$team}:after {
background-position: $x $y;
}
}
Output:
.teamA:before,
.teamA:after {
background-position: 0 20px;
}
.teamB:before,
.teamB:after {
background-position: 0 40px;
}
.teamC:before,
.teamC:after {
background-position: 0 60px;
}
.teamD:before,
.teamD:after {
background-position: 0 80px;
}
Another problem I face is where some teams would share the same background position, therefore the desired output would be something like such:
.teamA:before,
.teamA:after,
.teamAB:before,
.teamAB:after {
background-position: 0 20px;
}
.teamB:before,
.teamB:after {
background-position: 0 40px;
}
.teamC:before,
.teamC:after
.teamCB:before,
.teamCB:after {
background-position: 0 60px;
}
.teamD:before,
.teamD:after {
background-position: 0 80px;
}
Is it possible to group team names by some delimiter for it to compile into the same shared property?
$teams: 'A AB', B, 'CB, C', D;