本文介绍了使用数组值作为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有这些颜色:
$everlastingGreeN: #232553; $vividRed: #3435454; // and many more //and define those: $colors: (everlastingGreeN, vividRed);如何迭代这些值,以便可以使用颜色名称作为类名,然后使用值作为背景颜色?
How do I iterate those values so I can use the color name as the class name then the value as the background color?
@each $colors in $colors{ &.#{$colors} { background: {color value}; &:hover { background: darken({color value}, 10%); } } } 推荐答案您要查找的是列表列表.
What you're looking for is a list of lists.
$everlastingGreeN: #232553; $vividRed: #343545; // and many more //and define those: $colors: everlastingGreeN $everlastingGreeN, vividRed $vividRed; @each $color in $colors { &.#{nth($color, 1)} { background: nth($color, 2); &:hover { background: darken(nth($color, 2), 10%); } } }更多推荐
使用数组值作为变量
发布评论