【发布时间】:2018-01-02 13:12:04
【问题描述】:
我编写了以下循环来遍历团队列表以生成精灵图像的背景位置。我怎样才能把它变成一个函数,以便我可以传入 $teams、$X 和 $Y 值?
$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;
}
}
输出:
.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;
}
我面临的另一个问题是一些团队会共享相同的背景位置,因此所需的输出将是这样的:
.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;
}
是否可以通过某些分隔符对团队名称进行分组,以便编译成相同的共享属性?
$teams: 'A AB', B, 'CB, C', D;
【问题讨论】:
标签: css loops dictionary sass